Home Dashboard Directory Help
Search

Out-of-line method definition in template specialization by samaursa


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 730538
Opened: 3/11/2012 9:50:34 PM
Access Restriction: Public
1
Workaround(s)
view
0
User(s) can reproduce this bug

Description

The following code is, as far as I know, standard C++. It compiles on gcc but Visual Studio 2008 and 2010 fail to compile it.

    namespace cool
    {
     template <bool, typename = void> struct enable_if {};
     template <typename T> struct enable_if<true, T> { typedef T type; };
    
     template <typename T0, typename T1> struct is_same { enum { value = false }; };
     template <typename T> struct is_same<T, T> { enum { value = true }; };
    }
    
    struct BasePolicy {};
    struct BasePolicy2 {};
    struct Faz {};
    
    template <typename Policy,
    typename = typename cool::enable_if<cool::is_same<BasePolicy, Policy>::value || cool::is_same<BasePolicy2, Policy>::value>::type >
    struct Foo;
    
    template <typename Policy>
    struct Foo<Policy> {
     Foo();
    };
    
    template <typename Policy>
    Foo<Policy>::Foo() {
    }
    
    int main()
    {
     Foo<BasePolicy2> fb;
    }

Moving the constructor BACK to the class itself (i.e. the definition is now in-line so that the declaration is the definition as well) fixes the issue:

namespace cool
{
template <bool, typename = void> struct enable_if {};
template <typename T> struct enable_if<true, T> { typedef T type; };

template <typename T0, typename T1> struct is_same { enum { value = false }; };
template <typename T> struct is_same<T, T> { enum { value = true }; };
}

struct BasePolicy {};
struct BasePolicy2 {};
struct Faz {};

template <typename Policy,
typename = typename cool::enable_if<cool::is_same<BasePolicy, Policy>::value || cool::is_same<BasePolicy2, Policy>::value>::type >
struct Foo;

template <typename Policy>
struct Foo<Policy> {
Foo() {}
};

int main()
{
Foo<BasePolicy2> fb;
}
Details
Sign in to post a comment.
Posted by Microsoft on 5/9/2012 at 4:17 PM
Hello,

Thank you for reporting this bug. We're aware of this issue and have fixed it in current in-progress Visual Studio release. Next major release will have the fix.

Thanks,
Ulzii Luvsanbat
Visual C++ Team
Posted by Microsoft on 5/8/2012 at 12:11 AM
Thank you for submitting feedback on Visual Studio 11 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.

Posted by MS-Moderator01 on 3/11/2012 at 10:46 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Viorel_ on 3/12/2012 at 12:12 AM
Try this modified definition of class and constructor:


template <typename Policy, typename>
struct Foo
{
    Foo();
};

template <typename Policy, typename T>
Foo<Policy, T>::Foo()
{
}