title: May I declare a member type alias to a type in a surrounding scope, using the same name?
body: <p>I want a struct to contain a type alias to another type for metaprogramming purposes:</p>
  
  <pre><code>struct Foo {};
  
  struct WithNestedTypeAlias {
      using Foo = Foo;
  };
  </code></pre>
  
  <p>Then I can do stuff like <code>WithNestedTypeAlias::Foo</code> in a template etc.</p>
  
  <p>As I understand, this type alias is valid because it does not change the meaning of the <code>Foo</code> type. Clang compiles this happily.</p>
  
  <p>However, GCC complains:</p>
  
  <pre><code>test-shadow-alias.cpp:4:20: error: declaration of ‘using Foo = struct Foo’ [-fpermissive]
       using Foo = Foo;
                      ^
  test-shadow-alias.cpp:1:8: error: changes meaning of ‘Foo’ from ‘struct Foo’ [-fpermissive]
   struct Foo {};
          ^
  </code></pre>
  
  <p>Now I'm confused because I'm explicitly not changing the meaning of <code>Foo</code> from <code>struct Foo</code>.</p>
  
  <p>What is the correct behaviour for C++14? I know I can work around this by renaming the <code>struct Foo</code>, but I'd like to understand whether GCC's error is correct here.</p>
  
  <p>Notes:</p>
  
  <ul>
  <li><p>Tested with clang++ 3.8 and gcc 5.4, but <a href="https://godbolt.org/g/Pbc41X" rel="nofollow noreferrer">Godbolt suggests this hasn't changed in more recent GCC versions</a>.</p></li>
  <li><p>I looked at <a href="https://stackoverflow.com/q/26681873/1521179">Interaction between decltype and class member name shadowing an external name</a>, where the name of a <em>variable</em> may refer to either a variable in the outer scope or to a class member. In contrast, my question here is about a type alias. There is no ambiguity since <code>Foo</code> always refers to <code>::Foo</code> within the class scope. I don't see how the answer there applies to my problem.</p></li>
  <li><p>This is probably due to a misunderstanding of what type aliases actually are.</p></li>
  </ul>