Insert C ++ class name

According to the standard [class] / 2:

... The class name is also inserted into the scope of the class itself; this is known as the name of the introduced class ...

In addition, [basic.scope.pdecl] / 9:

The declaration point for the name class entered (section 9) immediately follows the opening bracket of the class definition.

Finally, [basic.lookup.classref] / 3 and its example:

If unqualified-id is a type name, the type name is looked up ...

struct A { }; struct B { struct A { }; void f(::A* a); }; void B::f(::A* a) { a-> ~ A(); // OK: lookup in *a finds the injected-class-name } 

So far, we can collect:

  • Within class A, there is a name A.
  • This name is declared when you open the class A bracket definition.
  • This name names the type.

If the above is correct, then why the following code cannot be compiled (in MSVC2015):

 struct inj {}; typedef struct inj::inj inj2; 

Error message

Error C2039 '{ctor}': is not a member of 'inj'

does not seem to conform to the standard:

Note. For example, the constructor is not an acceptable search result in the specified type specifier, therefore the constructor will not be used in place on behalf of the introduced class. -end note

+4
source share
1 answer

Since the following code compiles and works correctly on other compilers, this is a bug in MSVC2015.

 #include <boost/type_index.hpp> #include <iostream> struct inj { int g; }; typedef struct inj::inj inj2; int main() { inj2 ii; std::cout << boost::typeindex::type_id_with_cvr<decltype(ii)>().pretty_name() << '\n'; } 

UPDATE: Report an error .

+6
source

All Articles