title: prototype mismatch with decltype and auto
body: <p>Consider the following class:</p>
  
  <pre><code>class MyClass
  {
      int _id;
  public:
      decltype(_id) getId();
  };
  
  decltype(MyClass::_id) MyClass::getId()
  {
      return _id;
  }
  </code></pre>
  
  <p>It compiles fine.</p>
  
  <p>However when I make a template class out of it:</p>
  
  <pre><code>template &lt;class T&gt;
  class MyClass
  {
      int _id;
  public:
      decltype(_id) getId();
  };
  
  template &lt;class T&gt;
  decltype(MyClass&lt;T&gt;::_id) MyClass&lt;T&gt;::getId()
  {
      return _id;
  }
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>test.cpp:10:27: error: prototype for 'decltype (MyClass&lt;T&gt;::_id) MyClass&lt;T&gt;::getId()' does not match any in class 'MyClass&lt;T&gt;'
   decltype(MyClass&lt;T&gt;::_id) MyClass&lt;T&gt;::getId()                                                                                
                             ^
  test.cpp:6:19: error: candidate is: decltype (((MyClass&lt;T&gt;*)(void)0)-&gt;MyClass&lt;T&gt;::_id) MyClass&lt;T&gt;::getId()
       decltype(_id) getId();
                     ^
  </code></pre>
  
  <p>Why is that?<br>
  Why the different types</p>
  
  <ul>
  <li><code>decltype (MyClass&lt;T&gt;::_id) MyClass&lt;T&gt;::getId()</code></li>
  <li><code>decltype (((MyClass&lt;T&gt;*)(void)0)-&gt;MyClass&lt;T&gt;::_id)</code></li>
  </ul>
  
  <p>I could fix it by defining the body in the class:</p>
  
  <pre><code>template &lt;class T&gt;
  class MyClass
  {
      int _id;
  public:
      decltype(_id) getId() { return _id; }
  };
  </code></pre>
  
  <p>Trailing return type suffers a similar problem:</p>
  
  <pre><code>template &lt;class T&gt;
  class MyClass
  {
      int _id;
  public:
      auto getId() -&gt; decltype(_id);
  };
  
  template &lt;class T&gt;
  auto MyClass&lt;T&gt;::getId() -&gt; decltype(MyClass&lt;T&gt;::_id)
  {
      return _id;
  }
  </code></pre>
  
  <p>error:</p>
  
  <pre><code>test.cpp:10:6: error: prototype for 'decltype (MyClass&lt;T&gt;::_id) MyClass&lt;T&gt;::getId()' does not match any in class 'MyClass&lt;T&gt;'
   auto MyClass&lt;T&gt;::getId() -&gt; decltype(MyClass&lt;T&gt;::_id)
        ^
  test.cpp:6:10: error: candidate is: decltype (((MyClass&lt;T&gt;*)this)-&gt;MyClass&lt;T&gt;::_id) MyClass&lt;T&gt;::getId()
       auto getId() -&gt; decltype(_id);
            ^
  </code></pre>
  
  <ul>
  <li><code>decltype (MyClass&lt;T&gt;::_id) MyClass&lt;T&gt;::getId()</code></li>
  <li><code>decltype (((MyClass&lt;T&gt;*)this)-&gt;MyClass&lt;T&gt;::_id) MyClass&lt;T&gt;::getId()</code></li>
  </ul>
  
  <p>g++ 5.3.0</p>