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

    <tr>
        <th>Summary</th>
        <td>
            [clang] -Wshadow option produces a warning when explicitly capturing class member using the same name
        </td>
    </tr>

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

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

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

<pre>
    Starting from Clang 17.0.0 (built from source, but this also reproduces on Compiler Explorer) using -Wshadow flag now produces diagnostics for this code:
```
struct A
{
    int b = 5;

    int foo()
 {
        return [b = b] () 
        {
            return b;
 } ();
    }
};
```

I couldn't find this change in changelogs and there is no test for this type of capture in [warn-shadow-in-lambdas.cpp](https://github.com/llvm/llvm-project/blob/main/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp), so I think this is a bug that was introduced by the [commit](https://github.com/llvm/llvm-project/commit/0fb84bc7fdec1c20c2461e54d5c994939fe5b47f) that fixes #61105.

While technically this might be the case of 'shadowing' (I can't make any references to standard that either support or contradict my opinion), I don't think it has ever been considered a 'shadowing' case which should produce diagnostics and has been a somewhat common C++ pattern.

I don't see much value in that warning, since the name `b` referring to original class member is not available inside lambda body, and and the name `b` referring to the lambda member becomes available only when the other `b` is already not. Should it be considered shadowing?

Expected behavior: No warning generated
Actual behavior: `warning: declaration shadows a field of 'A' [-Wshadow]` diagnostics produced

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVcFu47oO_RplQzSw5diuF1k0zRjo5m26mNlSEm3rjSwZktw0f38h22kaDDDAvUWROJZIHh4ekhiC7i3RkZUnVp53OMfB-WNnXAw4opfDTjh1Pb5H9FHbHjrvRng1aHvI6322z4DxZzFrE9ej4GYvifFXEHOEOOgAaIIDT5N3apYUwFl4deOkDXn48TkZ58kz3sAcUoCnn2FA5S7QGezBugt8GSqNvXUhahmg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