title: C++ class name injection
body: <p>According to the standard [class]/2:</p>
  
  <blockquote>
    <p>… The class-name is also inserted into the scope of the class itself; this is known as the <em>injected-class-name</em>.…</p>
  </blockquote>
  
  <p>Moreover, [basic.scope.pdecl]/9:</p>
  
  <blockquote>
    <p>The point of declaration for an <em>injected-class-name</em> (Clause 9) is immediately following the opening brace of the class definition.</p>
  </blockquote>
  
  <p>Finally, [basic.lookup.classref]/3 and its example:</p>
  
  <blockquote>
    <p>If the unqualified-id is ~ <em>type-name</em>, the <em>type-name</em> is looked up …</p>
  </blockquote>
  
  <pre><code>struct A { };
  struct B {
      struct A { };
      void f(::A* a);
  };
  void B::f(::A* a) {
      a-&gt; ~ A(); // OK: lookup in *a finds the injected-class-name
  }
  </code></pre>
  
  <p>So far, we can gather:</p>
  
  <ol>
  <li>In the scope of a class A, there exists a name A.</li>
  <li>That name is declared at the opening of the definition brace of class A.</li>
  <li>That name names a type.</li>
  </ol>
  
  <p>If the above is correct, then <strong>why does the following code fails to compile</strong> (in MSVC2015):</p>
  
  <pre><code>struct inj
  {};
  
  typedef struct inj::inj inj2;
  </code></pre>
  
  <p>The error message </p>
  
  <blockquote>
    <p>Error C2039   '{ctor}': is not a member of 'inj'</p>
  </blockquote>
  
  <p>seems to be at odds with the standard:</p>
  
  <blockquote>
    <p>Note: For example, the constructor is not an acceptable lookup result in an elaborated-type-specifier so the constructor would not be used in place
    of the injected-class-name. —end note</p>
  </blockquote>