On Mon, Apr 1, 2013 at 10:42 AM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com" target="_blank">rjmccall@apple.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Mar 31, 2013, at 11:53 PM, ZhangXiongpang <<a href="mailto:zhangxiongpang@gmail.com">zhangxiongpang@gmail.com</a>> wrote:<br>
> Platform: linux, x86_64, clang++3.2, g++4.7.2<br>
><br>
> See the following code:<br>
> ------------------------------------------<br>
> namespace M {<br>
> namespace N {<br>
> enum class E; // #1<br>
> }<br>
> using N::E; // #2<br>
> }<br>
> enum class M::E { e1, e2 }; // #3<br>
> M::E e; // clang++ reports ambiguous<br>
> ------------------------------------------<br>
> g++ treats #3 as a defination of M::N::E, while clang++ treats it as a<br>
> defination of M::E<br>
><br>
> I saw paragraph 4 in [dcl.enum]:<br>
> ------------------------------------------<br>
> "If the enum-key is followed by a nested-name-specifier, the enum-specifier<br>
> shall refer to an enumeration that<br>
> was previously declared directly in the class or namespace to which the<br>
> nested-name-specifier refers (i.e.,<br>
> neither inherited nor introduced by a using-declaration), [...]"<br>
> ------------------------------------------<br>
><br>
> So I think it is obvious that g++ does not obey C++ standard.<br>
> But I'm not sure whether clang++ strictly obey the standard.<br>
> My understanding of the standard's description has double meanings:<br>
> ------------------------------------------<br>
> (1) the enum-specifier shall refer to an enumeration that was previously<br>
> declared directly in the namespace<br>
> (2) the enum-specifier shall refer to an enumeration that was not introduced<br>
> by a using-declaration<br>
> ------------------------------------------<br>
> And the (1) make me confused, I'm not sure whether the using-declaration(#2)<br>
> implies a opaque-enum-declaration of E in namespace M.<br>
> If not, then perhaps clang++ shall report error when parsing #3.<br>
> Is my understanding right?<br>
<br>
</div></div>I agree; neither compiler is correct here.</blockquote><div><br></div><div>Class types have the same rule (see [class]p11) and we don't enforce that either. For instance:</div><div><br></div><div>namespace M {</div>
<div> namespace N {</div><div> struct S;</div><div> }</div><div> using N::S;</div><div>}</div><div>struct M::S { };</div><div>M::S m; // error, ambiguous</div><div><br></div><div>FWIW, g++ accepts both of these (even with -pedantic) and EDG accepts both outside its strict mode.</div>
</div>