title: decltype of entity that may be captured: should it yield the type of the entity outside of the lambda?
body: <p>Consider this simple self-contained code:</p>
  <pre><code>template&lt;typename T&gt;
  void foo();
  
  void bar() {
      int i;
      auto l = [&amp;i]() -&gt; decltype(auto) {
          decltype(auto) x = i;
          foo&lt;decltype(x)&gt;();
          foo&lt;decltype(i)&gt;();
          return static_cast&lt;decltype(i)&gt;(i);
      };
      l();
      foo&lt;decltype(l())&gt;();
  }
  </code></pre>
  <p>GCC Generates the following:</p>
  <pre><code>bar():
          sub     rsp, 8
          call    void foo&lt;int&amp;&gt;()
          call    void foo&lt;int&gt;()
          add     rsp, 8
          jmp     void foo&lt;int&gt;()
  </code></pre>
  <p>Clang Generates the following:</p>
  <pre><code>bar():                                # @bar()
          push    rax
          call    void foo&lt;int&gt;()
          call    void foo&lt;int&gt;()
          pop     rax
          jmp     void foo&lt;int&gt;()                     # TAILCALL
  </code></pre>
  <p>MSVC Generates the following:</p>
  <pre><code>void bar(void) PROC                                        ; bar, COMDAT
  $LN8:
          sub     rsp, 40                             ; 00000028H
          call    void foo&lt;int &amp;&gt;(void)                  ; foo&lt;int &amp;&gt;
          call    void foo&lt;int &amp;&gt;(void)                  ; foo&lt;int &amp;&gt;
          add     rsp, 40                             ; 00000028H
          jmp     void foo&lt;int &amp;&gt;(void)                        ; foo&lt;int &amp;&gt;
  void bar(void) ENDP   
  
   
  </code></pre>
  <p>It seems all three compiler disagree. Which one is right and what part of the C++ standard confirms it?</p>
  <p>In my mind, <code>decltype(i)</code> should always be <code>int</code>, and never <code>int&amp;</code>, no matter if it is captured or not.</p>
  <p><a href="https://gcc.godbolt.org/z/G6jdTr579" rel="noreferrer">Obligatory compiler explorer link</a></p>