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

    <tr>
        <th>Summary</th>
        <td>
            False positive warning with `-Wshadow` when using structured binding and lambda capture
        </td>
    </tr>

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

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

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

<pre>
    Clang 17.0.1 started to emit shadowing warning in the following case. There is lambda capture of an entity[^1] made with structured binding, and entity has the same name as the capture name. See [example](https://godbolt.org/z/MbeEYM8Yj) on godbolt or below. The warning looks like false positive, because:
* It is not possible to use name from outer scope (from `get_descriptors` in the example) in lambda without capturing, so no shadowing possible.
* Note that there is no warning in the [similar case](https://godbolt.org/z/eqYPsWfvM) without structured binding.

This behavior is annoying, because it forces to come up with new names where old ones should work.

Affected versions:
* Clang 17.0.1
* Clang trunk (on godbolt)

Not affected versions:
* 16.0.0 and older.

Repeating problematic example with warning as a comment for completeness here:
```cpp
#include <algorithm>
#include <map>
#include <vector>

struct Descriptor
{
    // some fields needed for descriptor
};

struct Metadata
{

};

using DescriptorMap = std::map<int, Descriptor>;

std::pair<DescriptorMap, Metadata> get_descriptor_map_with_metadata()
{
    return std::pair(DescriptorMap
        {
            { 1, Descriptor{} },
 { 42, Descriptor{} },
        },
 Metadata{});
}

std::vector<Descriptor> get_descriptors(const std::vector<int> & ids)
{
    auto [id_to_descriptor, metadata] = get_descriptor_map_with_metadata();

    std::vector<Descriptor> descriptors;

    const auto fill_descriptors =
        // warning: declaration shadows a structured binding [-Wshadow]
 [id_to_descriptor = std::move(id_to_descriptor), &metadata, &descriptors]
 (const int id)
        {
 descriptors.push_back(id_to_descriptor.at(id));
        };

 std::for_each(begin(ids), end(ids), fill_descriptors);

    return descriptors;
}
```

[^1]: I know that structured binding creates not exactly a variable, hence I call it "entity".
</p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