[clang] [clang-repl] Names declared in if conditions and for-init statements are local to the inner context (C++ 3.3.2p4) (PR #84150)

Vassil Vassilev via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 6 06:23:47 PST 2024


Stefan =?utf-8?q?Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>,
Stefan =?utf-8?q?Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>,
Stefan =?utf-8?q?Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>,
Stefan =?utf-8?q?Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>,
Stefan =?utf-8?q?Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>,
Stefan =?utf-8?q?Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/84150 at github.com>


================
@@ -41,3 +40,23 @@ for (; i > 4; --i) { printf("i = %d\n", i); };
 
 int j = i; printf("j = %d\n", j);
 // CHECK-NEXT: j = 4
+
+{++i; printf("i = %d (global scope)\n", i);}
+// CHECK-NEXT: i = 5
+
+while (int i = 1) { printf("i = %d (while condition)\n", i--); break; }
+// CHECK-NEXT: i = 1
+
+if (int i = 2) printf("i = %d (if condition)\n", i);
+// CHECK-NEXT: i = 2
+
+switch (int i = 3) { default: printf("i = %d (switch condition)\n", i); }
+// CHECK-NEXT: i = 3
+
+for (int i = 4; i > 3; --i) printf("i = %d (for-init)\n", i);
----------------
vgvassilev wrote:

Maybe a range-based for-loop test won't hurt here...

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


More information about the cfe-commits mailing list