title: Clang vs. GCC: Error in unevaluated context breaks SFINAE
body: <p>While continuing work from <a href="https://stackoverflow.com/a/38347040/678093">my previous question</a>, I came across different behavior of clang and GCC.<br>
  I need to check the member function pointer because I need to know if the function is inherited or not.</p>
  
  <p>When comparing member function pointers in an SFINAE context, member function <code>Foo::foo()</code> exists, but its body contains code (<code>x.hello()</code>) which eventually does not compile.</p>
  
  <p>The following code compiles with clang.
  GCC however seems to evaluate the function body of <code>Foo::foo()</code> and exits with an error (<code>'struct Caller' has no member named 'hello'</code>), despite being in an unevaluated SFINAE context (or so I hope).</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;type_traits&gt;
  
  struct Foo
  {
      template &lt;typename T&gt; void foo(T&amp;&amp; x) { x.hello(); }
  };
  
  struct Caller
  {    
      template &lt;typename T&gt;
      auto call(T&amp;&amp; x) -&gt; decltype(
          std::enable_if_t&lt;
              std::is_same&lt;
                  decltype(&amp;T::template foo&lt;decltype(*this)&gt;),
                  void (T::*)(decltype(*this))
              &gt;::value
          &gt;())
      {
          //x.foo(*this);
      }
  };
  
  int main()
  {
    Caller c;
    c.call(Foo());
  }
  </code></pre>
  
  <p>I tested with:</p>
  
  <ul>
  <li>clang 3.8.0</li>
  <li>g++ 6.1.0</li>
  </ul>
  
  <p>Compiler options for both: <code>-std=c++14 -O2 -Wall -pedantic -pthread</code></p>
  
  <p><kbd><a href="http://coliru.stacked-crooked.com/a/15f0f4fa3c2698fd" rel="nofollow noreferrer">live example</a></kbd></p>
  
  <p><strong>My questions:</strong></p>
  
  <ol>
  <li>who is right? Clang or GCC?</li>
  <li>How can I get the code to compile with GCC?</li>
  </ol>