title: typename resolution in cases of ambiguity
body: <p>I was playing with Visual Studio and templates. </p>
  
  <p>Consider this code</p>
  
  <pre><code>struct Foo
  {
    struct Bar
    {
    };
  
    static const int Bar=42;
  };
  
  template&lt;typename T&gt;
  void MyFunction()
  {
    typename T::Bar f;  
  }
  
  int main()
  {
      MyFunction&lt;Foo&gt;();
      return 0;
  }
  </code></pre>
  
  <p>When I compile this is either Visual Studio 2008 and 11, I get the following error</p>
  
  <p><code>error C2146: syntax error : missing ';' before identifier 'f'</code></p>
  
  <p>Is Visual Studio correct in this regard ? Is the code violating any standards ?</p>
  
  <p>If I change the code to </p>
  
  <pre><code>struct Foo
  {
    struct Bar
    {
    };
  
    static const int Bar=42;
  };
  
  
  void SecondFunction( const int&amp; )
  {
  }
  
  template&lt;typename T&gt;
  void MyFunction()
  {
    SecondFunction( T::Bar ); 
  }
  
  int main()
  {
      MyFunction&lt;Foo&gt;();
      return 0;
  }
  </code></pre>
  
  <p>it compiles without any warnings.  In Foo::BLAH a <strong>member</strong> preferred over a <strong>type</strong> in case of conflicts ?</p>
  
  <p><strong>EDIT  Tests on G++ 4.2.1</strong> </p>
  
  <pre><code>struct Foo
  {
    static const int Bar=42;
  };
  
  
  void SecondFunction(const int&amp; x)
  {
  }
  
  template&lt;typename T&gt;
  void MyFunction()
  {
    int x = Foo::Bar;
  }
  
  int main()
  {
    MyFunction&lt;Foo&gt;();
    return 0;
  }
  </code></pre>
  
  <p>compiles OK.</p>
  
  <pre><code>struct Foo
  {
    static const int Bar=42;
  };
  
  
  void SecondFunction(const int&amp; x)
  {
  }
  
  template&lt;typename T&gt;
  void MyFunction()
  {
    SecondFunction(T::Bar);
  }
  
  int main()
  {
    MyFunction&lt;Foo&gt;();
    return 0;
  }
  </code></pre>
  
  <p>Gives me these errors</p>
  
  <p><strong>Undefined symbols:
    "Foo::Bar", referenced from:
        void MyFunction()  in cck498aS.o
  ld: symbol(s) not found
  collect2: ld returned 1 exit status</strong></p>