[cfe-dev] [C++11] a question involving forward declarations for enums

John McCall rjmccall at apple.com
Mon Apr 1 10:42:20 PDT 2013


On Mar 31, 2013, at 11:53 PM, ZhangXiongpang <zhangxiongpang at gmail.com> wrote:
> Platform: linux, x86_64, clang++3.2, g++4.7.2
> 
> See the following code:
> ------------------------------------------
> namespace M {
>    namespace N {
>        enum class E; // #1
>    }
>    using N::E;       // #2
> }
> enum class M::E { e1, e2 }; // #3
> M::E e; // clang++ reports ambiguous
> ------------------------------------------
> g++ treats #3 as a defination of M::N::E, while clang++ treats it as a
> defination of M::E
> 
> I saw paragraph 4 in [dcl.enum]:
> ------------------------------------------
> "If the enum-key is followed by a nested-name-specifier, the enum-specifier
> shall refer to an enumeration that
> was previously declared directly in the class or namespace to which the
> nested-name-specifier refers (i.e.,
> neither inherited nor introduced by a using-declaration), [...]"
> ------------------------------------------
> 
> So I think it is obvious that g++ does not obey C++ standard.
> But I'm not sure whether clang++ strictly obey the standard.
> My understanding of the standard's description has double meanings:
> ------------------------------------------
> (1) the enum-specifier shall refer to an enumeration that was previously
> declared directly in the namespace
> (2) the enum-specifier shall refer to an enumeration that was not introduced
> by a using-declaration
> ------------------------------------------
> And the (1) make me confused, I'm not sure whether the using-declaration(#2)
> implies a opaque-enum-declaration of E in namespace M.
> If not, then perhaps clang++ shall report error when parsing #3.
> Is my understanding right?

I agree;  neither compiler is correct here.

John.



More information about the cfe-dev mailing list