title: "Cannot call member function ... without object" inside unevaluated context - GCC bug?
body: <p>The following program compiles fine with Clang:</p>
  
  <pre><code>template&lt; typename &gt; struct X
  {
    void foo() {}
  
    auto bar() -&gt; decltype( X::foo() )
    {
      return foo();
    }
  };
  
  int main()
  {
    X&lt;int&gt;().bar();
  }
  </code></pre>
  
  <p>But GCC 4.8.1 gives:</p>
  
  <pre><code>main.cpp: In instantiation of 'struct X&lt;int&gt;':
  main.cpp:13:10:   required from here
  main.cpp:5:34: error: cannot call member function 'void X&lt; &lt;template-parameter-1-1&gt; &gt;::foo() [with &lt;template-parameter-1-1&gt; = int]' without object
     auto bar() -&gt; decltype( X::foo() )
                                    ^
  main.cpp: In function 'int main()':
  main.cpp:13:12: error: 'struct X&lt;int&gt;' has no member named 'bar'
     X&lt;int&gt;().bar();
              ^
  </code></pre>
  
  <p><a href="http://coliru.stacked-crooked.com/a/307f5bfa29ab8d45" rel="nofollow"><strong>Live example</strong></a></p>
  
  <p>When I change the code to <code>decltype( std::declval&lt;X&gt;().foo() )</code> GCC compiles it.</p>
  
  <p>Is this a bug in GCC (and is there an existing bug report for it or should report it?) or is there anything wrong with my code?</p>