Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

We found something similar to the following (don't ask ...):

namespace N {
    struct A { struct B; };
}

struct A { struct B; };

using namespace N;

struct ::A::B {}; // <- point of interest

Interestingly, this compiles fine with VS2005, icc 11.1 and Comeau (online), but fails with GCC:

global qualification of class name is invalid before '{' token

From C++03, Annex A, it seems to me like GCC is right:

  • the class-head can consist of nested-name-specifier and identifier
  • nested-name-specifier can't begin with a global qualification (::)
  • obviously, neither can identifier

... or am i overlooking something?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
600 views
Welcome To Ask or Share your Answers For Others

1 Answer

I think you are getting it right: GCC implements the standard to the letter in this case, while the others implement it less strict (have a look at issue #355).

You could do the following to work-around the limitation of the syntax

struct identity< ::A >::type::B {}; 

Or you use an explicit named typedef

typedef ::A AHidden;
struct AHidden::B { };

Or, of course, you exchange the order of using namespace and the nested class definition. Notice that Annex A is informative only. The normative text is at clauses 5.1/7 and 9.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...