Commit d8c2607
[clang][Sema] Fix false positive -Wshadow with structured binding captures (llvm#157667)
Previously, lambda init captures of structured bindings were incorrectly
classified as regular shadow warnings (shown with `-Wshadow`), while
regular parameter captures were correctly classified as
`uncaptured-local` warnings (shown only with `-Wshadow-all`). This
created inconsistent behavior:
```cpp
void foo1(std::pair<int, int> val) {
[val = std::move(val)](){}(); // No warning with -Wshadow (correct)
}
void foo2(std::pair<int, int> val) {
auto [a, b] = val;
[a = std::move(a)](){}(); // Warning with -Wshadow (incorrect)
}
```
The fix extends the existing lambda capture classification logic in
`CheckShadow()` to handle `BindingDecl` consistently with `VarDecl`,
ensuring both cases show no warnings with `-Wshadow` and
`uncaptured-local` warnings with `-Wshadow-all`.
Fixes llvm#68605.
---------
Co-authored-by: Mariya Podchishchaeva <[email protected]>1 parent 44061d1 commit d8c2607
File tree
4 files changed
+111
-17
lines changed- clang
- docs
- lib/Sema
- test/SemaCXX
4 files changed
+111
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
319 | 324 | | |
320 | 325 | | |
321 | 326 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8395 | 8395 | | |
8396 | 8396 | | |
8397 | 8397 | | |
8398 | | - | |
| 8398 | + | |
8399 | 8399 | | |
8400 | 8400 | | |
8401 | 8401 | | |
| |||
8492 | 8492 | | |
8493 | 8493 | | |
8494 | 8494 | | |
8495 | | - | |
| 8495 | + | |
| 8496 | + | |
| 8497 | + | |
8496 | 8498 | | |
8497 | 8499 | | |
8498 | 8500 | | |
| |||
8521 | 8523 | | |
8522 | 8524 | | |
8523 | 8525 | | |
8524 | | - | |
8525 | | - | |
8526 | | - | |
8527 | | - | |
8528 | | - | |
8529 | | - | |
8530 | | - | |
8531 | | - | |
8532 | | - | |
8533 | | - | |
8534 | | - | |
8535 | | - | |
| 8526 | + | |
| 8527 | + | |
| 8528 | + | |
| 8529 | + | |
| 8530 | + | |
| 8531 | + | |
| 8532 | + | |
| 8533 | + | |
| 8534 | + | |
| 8535 | + | |
| 8536 | + | |
| 8537 | + | |
| 8538 | + | |
| 8539 | + | |
| 8540 | + | |
| 8541 | + | |
| 8542 | + | |
| 8543 | + | |
| 8544 | + | |
| 8545 | + | |
| 8546 | + | |
8536 | 8547 | | |
8537 | 8548 | | |
8538 | 8549 | | |
| |||
8579 | 8590 | | |
8580 | 8591 | | |
8581 | 8592 | | |
8582 | | - | |
| 8593 | + | |
| 8594 | + | |
8583 | 8595 | | |
8584 | 8596 | | |
8585 | 8597 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
262 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
263 | 267 | | |
264 | 268 | | |
| 269 | + | |
265 | 270 | | |
266 | 271 | | |
267 | 272 | | |
0 commit comments