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

ZhangXiongpang zhangxiongpang at gmail.com
Sun Mar 31 23:53:31 PDT 2013


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?



--
View this message in context: http://clang-developers.42468.n3.nabble.com/C-11-a-question-involving-forward-declarations-for-enums-tp4031236.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list