Search

Visual C++ does not handle based enums correctly by Alf P. Steinbach, except MS doesn't accept it

Closed
as Fixed Help for as Fixed

3
0
Sign in
to vote
Type: Bug
ID: 699236
Opened: 11/4/2011 9:31:43 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
3
User(s) can reproduce this bug
Up to and including Visual C++ 11 (I only have the preview of that compiler) the following code fails to compile:

#ifdef _MSC_VER
# pragma warning( disable: 4480 )     // enum base as "nonstandard extension"
#endif
enum ShouldBeFine: char { hola };

enum Choice { a, b, c };

template< Choice c > struct Traits;

template<> struct Traits<a> { typedef char Type; };
template<> struct Traits<b> { typedef wchar_t Type; };
template<> struct Traits<c> { typedef long Type; };

template< Choice c >
struct Blah
{
    enum X: typename Traits<c>::Type {};
};

int main()
{}
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 11 Developer Preview

Steps to reproduce

#ifdef _MSC_VER
# pragma warning( disable: 4480 )     // enum base as "nonstandard extension"
#endif
enum ShouldBeFine: char { hola };

enum Choice { a, b, c };

template< Choice c > struct Traits;

template<> struct Traits<a> { typedef char Type; };
template<> struct Traits<b> { typedef wchar_t Type; };
template<> struct Traits<c> { typedef long Type; };

template< Choice c >
struct Blah
{
    enum X: typename Traits<c>::Type {};
};

int main()
{}

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

D:\dev\test\error> (cl /nologo- 2>&1) | find /i "c++"
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 17.00.40825.2 for 80x86

D:\dev\test\error> cl msvc_enum_base.cpp
msvc_enum_base.cpp
msvc_enum_base.cpp(17) : error C3254: 'Blah<c>' : class contains explicit override 'Type' but does not derive from an in
terface that contains the function declaration
        msvc_enum_base.cpp(18) : see reference to class template instantiation 'Blah<c>' being compiled
msvc_enum_base.cpp(17) : error C2838: 'Type' : illegal qualified name in member declaration
msvc_enum_base.cpp(17) : error C2473: 'Type' : looks like a function definition, but there is no parameter list.

D:\dev\test\error> _

Expected results

d:\dev\test\error> g++ msvc_enum_base.cpp -std=c++0x

d:\dev\test\error> _
File Attachments
File Name Submitted By Submitted On File Size  
msvc_enum_base.cpp 11/4/2011 455 bytes
Sign in to post a comment.
Posted by Microsoft on 11/17/2011 at 8:07 PM
Hi: this issue has been fixed. The fix should show up in a future release of Visual C++.

Thank you for reporting the issue.

Jonathan Caves
Visual C++ Compiler Team
Posted by MS-Moderator09 [Feedback Moderator] on 11/6/2011 at 7:31 PM
Thank you for submitting feedback on Visual Studio 2010 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 11/6/2011 at 6:30 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.