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

    <tr>
        <th>Summary</th>
        <td>
            ## clang allows reference to non-static data member in parameters of lambda in member function
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          Rush10233
      </td>
    </tr>
</table>

<pre>
    The following code is accepted by clang:

```c++
struct A
{
 const int i=1;
  void foo()
  {
    [&](int a[i]){}; 
 //[&](int a=i){}; 
  }
};
```
The lambda parameter `int a[i]` seems to be illegal, because `this` pointer will not be captured in the parameter field. GCC and EDG reject it but give a puzzling diagnostic complaining that `i` is not a constant:

```c++
<source>: In member function 'void A::foo()':
<source>:7:15: error: size of array 'a' is not an integral constant-expression
    7 |     [&](int a[i]){};
```

Note that clang will generate an error if `i` is referenced by default argument value instead of array length value.

```c++
<source>:8:15: error: default argument references 'this'
    8 |     [&](int a=i){}; 
```

[https://godbolt.org/z/bKKW8jzne](https://godbolt.org/z/bKKW8jzne)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVF2PqzYQ_TXmZbQR2CHAAw-b5OaqulIfqkp9HvAAvjI2sk1uN7--MuRjtxtVW8kisT0fx-fMDHqvekNUs3zP8mOCcxisq_-Y_ZClXIiksfKt_nMg6KzW9pcyPbRWEigP2LY0BZLQvEGr0fRMvLL0yNLbd5euq2V8H9dy6oOb2wA3m-J6DK01PoAyARQTx4yJ2wWcrZLQWct4yXh1O314AkBEz3csPzJexhDI8r1atlW0K45M7OFqzvgprk8e4qiemUPcXrEe76jub1u3kSCNYyMRJnQ4UiAHbJd-wLJLwRONHoKFhkBpTT1qxg_QUIuzp-gRBuWj5WSViUF-Ka3B2BA9WpzC7EiCMhAGepeqU6TlBr4fDoBGwrfjd3D0k9oAKkAzB-jVmQBhmi8XHTWUCntjfVAttHacNCoTj8OAYcEdISi_JMZVGjThS_oycfB2di0x8Y2JV_jNwEhjE0HOpg3KGmC8WDR9jQHF60NaXjxSfAwTL7I8xiPnrIt_vLoQ2A7QOXyLMZHx4g7axFKi3qG-w3-hvydH3itrHpVTACsO8NUaeir--v3dBlr5W3phFa4nQw4DRTwLcFDde34ddeTItGsTSepw1gHQ9fNIJsAZ9UygjA-E8vFWTaYPw3q7-d-KlJ-p_JT4jstHYpea5MWDtPI_SHveRk8pY_l-CGHyUfSlKXsrG6vDxrqe8dOF8VPz48df5c-LoTXF1815lchayEpUmFCdFZwXRcZFlgy1KKnKm1LyDKutRCywlGmRpaLItkW-bRJV85Rv0zLdZpkQebbpyqbMeFrJvOrKbLdj25RGVHqj9XmM6RPl_Ux1lmZlmSUaG9L-NlJdHa1emrn3bJtq5YN_-AUVNNWMC8bFtXAwztl3pRHHhbHmxQeM7Sox4K2jlHnMAB_r4zqD1KeeS2an63-xp8IwN5vWjoyfIqDrz8vkbBwdjJ-WV3nGT9eHnWv-TwAAAP__zEfR1A">