title: How to get the return type of a member function from within a class?
body: <p>The following program yields a compilation error with <code>clang</code>, though it passes on other compilers:</p>
  
  <pre><code>#include &lt;utility&gt;
  
  struct foo
  {
    auto bar() -&gt; decltype(0)
    {
      return 0;
    }
  
    using bar_type = decltype(std::declval&lt;foo&gt;().bar());
  };
  
  int main()
  {
    return 0;
  }
  </code></pre>
  
  <p><code>clang</code> yields:</p>
  
  <pre><code>$ clang -std=c++11 clang_repro.cpp 
  clang_repro.cpp:10:48: error: member access into incomplete type 'foo'
    using bar_type = decltype(std::declval&lt;foo&gt;().bar());
                                                 ^
  clang_repro.cpp:3:8: note: definition of 'foo' is not complete until the closing '}'
  struct foo
         ^
  1 error generated.
  </code></pre>
  
  <p>Is this program illegal, and if so, is there a correct way to define <code>foo::bar_type</code>?</p>
  
  <p><code>clang</code> details:</p>
  
  <pre><code>$ clang --version
  Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)
  Target: x86_64-pc-linux-gnu
  Thread model: posix
  </code></pre>