Topic: Using non-defined class as nested name specifier


Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Tue, 2 Feb 2010 17:43:47 CST
Raw View
Every class has an injected class name (9/2).

"A class-name is inserted into the scope in which it is declared immediately
after the class-name is seen. The class-name is also inserted into the scope
of the class itself; this is known as the injected-class-name."

Why is the following not possible?

class B;
class B::B *b;

Is there some constraint that a qualifier to a class must nominate a
defined/being-defined class? I tried, and comeau/gcc/clang reject that.

Notice that using incomplete types as nested name specifiers is fine:

struct A {
 typedef int type;
 A::type a; // valid
};

There must be a different reason. Any idea? Thanks!

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: CornedBee <wasti.redl@gmx.net>
Date: Wed, 3 Feb 2010 11:51:58 CST
Raw View
On Feb 3, 12:43 am, "Johannes Schaub (litb)" <schaub-johan...@web.de>
wrote:
> Every class has an injected class name (9/2).
>
> "A class-name is inserted into the scope in which it is declared immediately
> after the class-name is seen. The class-name is also inserted into the scope
> of the class itself; this is known as the injected-class-name."
>
> Why is the following not possible?
>
> class B;
> class B::B *b;

[class.qual] (3.4.3.1)p2 says that B::B refers to the constructor when
it is an acceptable lookup result. Which the compiler apparently
thinks it is in this case; I'm not sure if it is right.

Sebastian


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Wed, 3 Feb 2010 16:17:09 CST
Raw View
CornedBee wrote:

> On Feb 3, 12:43 am, "Johannes Schaub (litb)" <schaub-johan...@web.de>
> wrote:
>> Every class has an injected class name (9/2).
>>
>> "A class-name is inserted into the scope in which it is declared
>> immediately after the class-name is seen. The class-name is also inserted
>> into the scope of the class itself; this is known as the
>> injected-class-name."
>>
>> Why is the following not possible?
>>
>> class B;
>> class B::B *b;
>
> [class.qual] (3.4.3.1)p2 says that B::B refers to the constructor when
> it is an acceptable lookup result. Which the compiler apparently
> thinks it is in this case; I'm not sure if it is right.
>
I put the "class" in front because i wanted it not be an acceptable lookup
result (in an elaborated type specifier, non-type names are ignored). This
was the primary force for changing 3.4.3.1/p2 (another case is when
it appears as a base-class specifier): http://www.open-
std.org/jtc1/sc22/wg21/docs/cwg_defects.html#318 (notice the example given).

So there must be another reason :( I feel the Standard means that the
injected class name is introduced only when a class definition appears. 9.2
could be read like that i think, but i feel like i may have missed
something. I think i will send a DR if noone comes up with an obvious
solution :)


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]