[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug c++/53815] New: Explicit specialization of member enumeration of a class template
From:       "potswa at mac dot com" <gcc-bugzilla () gcc ! gnu ! org>
Date:       2012-06-30 5:44:58
Message-ID: bug-53815-4 () http ! gcc ! gnu ! org/bugzilla/
[Download RAW message or body]

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53815

             Bug #: 53815
           Summary: Explicit specialization of member enumeration of a
                    class template
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: potswa@mac.com


C++11 quietly added a bullet point to the middle of the list of things that can
be explicitly specialized (14.7.3/1 [templ.expl.spec]):

  - member enumeration of a class template

So, this should compile:

template <class x> struct Foo
{
    int getX(x *p) { return(0); }
    enum E12 { a };
};

template <> int Foo<int>::getX(int*)
{
    return(-15);
}

template <> enum Foo<int>::E12
{
    a, b, c
};

It fails with "redeclaration of ‘Foo<int>::E12 Foo<int>::a'". Deleting "a" from
the primary template results in "enumerator value 2 is too large for underlying
type ‘unsigned int'". Adding an explicit underlying type of "int" to the
specialization results in "underlying type mismatch in enum ‘enum
Foo<int>::E12'".

Then, adding the same underlying type to the primary template results in
successful compilation. The enumerators of the specialization can be accessed
from outside the class scope, but the enumerators of the hidden primary
template are visible as well.

The feature is rather bizarre, IMHO. This was caught by a StackOverflow user,
although it's not clear he's even aware of C++11 but may have just always
expected it to be legal. http://stackoverflow.com/q/11271553/153285
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic