[clang] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 9 03:14:55 PST 2024


================
@@ -179,3 +179,64 @@ void f() {
 #endif
 }
 }
+
+namespace GH71976 {
+#ifdef AVOID
+struct A {
+  int b = 5;
+  int foo() {
+    return [b = b]() { return b; }(); // no -Wshadow diagnostic, init-capture does not shadow b due to not capturing this
+  }
+};
+
+struct B {
+  int a;
+  void foo() {
+    auto b = [a = this->a] {}; // no -Wshadow diagnostic, init-capture does not shadow a due to not capturing his
+  }
+};
+
+struct C {
+  int b = 5;
+  int foo() {
+    return [a = b]() {
+      return [=, b = a]() { // no -Wshadow diagnostic, init-capture does not shadow b due to outer lambda
+        return b;
----------------
cor3ntin wrote:

Should we test we get a warning for a?

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


More information about the cfe-commits mailing list