[Mlir-commits] [clang-tools-extra] [mlir] [libcxxabi] [compiler-rt] [clang] [flang] [llvm] [libc] [libcxx] [openmp] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

Nikolas Klauser llvmlistbot at llvm.org
Thu Jan 11 08:32:02 PST 2024


philnik777 wrote:

> @philnik777 I agree strongly with @Fznamznon. If `this` is not captured there is no actual shadowing in that they do not occupy encompassing scope, and so removing one declaration would not give you access to the other variable.

I don't disagree that this is technically not shadowing, but I don't think that's clear from a users perspective. e.g.

```c++
void someFunc(int someVal) {
  // assume 100 LoC here

  auto someLambda = [](int someVal) {
    // another 100 LoC here
    return someVal + 40; // IMO it's trivial to confuse this with the `someVal` from `someFunc`
  };
}
```
It looks like Clang even has a warning for this specific case and GCC considers it shadowing too: https://godbolt.org/z/Y16njoPxh, which makes me think that people want this - at least as a separate flag.


https://github.com/llvm/llvm-project/pull/74512


More information about the Mlir-commits mailing list