<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/131452>131452</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Lambda in template context fails to implicitly capture const local variable (accepted by GCC/MSVC)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          starbugs-qurong
      </td>
    </tr>
</table>

<pre>
    In a template context, when a lambda inside a function template uses a const-qualified local variable without explicit capture, Clang incorrectly rejects the code while GCC and MSVC accept it according to the C++ standard. If we replace the function template with a regular function then clang does not emit an error. 

For this program:

template<typename T> 
void f() {
    const int i = 42;
 auto k = [] {  //  Error in Clang
        return i;  // Missing capture of 'i' in template context
    }();
}

This causes an error in clang, but MSVC and GCC accept it. 

Compiler Explorer link: https://godbolt.org/z/67T68WMhs
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxkU89zszYQ_WuWy048ILAxBw4OCZ1vpjk1054FWoP6CYlPWuy4f31HYDedxBcD--vte_tkCHqwRDXsn2H_ksiFR-frwNJ3yxCefi3e2SHpnLrVPyxKZJpmI5mwd5bpg0E0eB0phoycOiVR26AVocTzYnvWzn7WLIECylga-OnXIo0-a1JoXC8NXqTXsjOEV82jWxjpYza614y9nHnxFEc1RtoBte2d99SzuaGnv6nngDxGTIrwOmpD-FvToLQK3_74s0HZ9zQzao5PzittB2S3ljQgnkE8Y2BplfRqhz_OeCX0NBvZ05rzfZEIESV6GhYj_f8SIhP9ilE5CmgdI01xrkXy3vkdQnqC9NQ6jzzqgLN3g5cT5Kct8BgBecO3maycCN8hf411F6cVnkEcQVQI5TOkJ0Tc6ERtGTVC_oKFgHyNyYUd_ly_bfLGIkQQLYgW8TUCQm03Uu_N4s8TL96ihvwz-02HEGm7a4HujCBKDaKMHb5dxdYMypcN7QYovq5LvsfNe7mdw52Z2GZlLsrcLXxXzqpNyoeCDwIbN83akMfXj9k4Tx6Ntj8hP-HIPIfI5wp8cKpzhnfODyDaf0C0h_L9cPzrbQyJqnNV5ZVMqM7KQqT58XgskrEuBJVHUvtDWdGh6KqsojLtVHZQh0OZSpHoWqRin-bZPsuKTBS7dN9laVl1eZF2ednlUKQ0SW12xlymODvRISxUZ3lW7EViZEcmrJ4TwtIV1ygIES3o61j0FO0HRWp04PDZhjUbqn9_OO0b8XiW2oR43Hra3GNu_2m2HcoXt4E4buSSwu4WyQbRRu5BVMniTf2FT83j0u16N4FoI6z739PsXTQiiHZdJoBo79teavFvAAAA__8bLW12">