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

Stefan Gränitz via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 6 08:47:03 PST 2024


================
@@ -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);
----------------
weliveindetail wrote:

Yes good point, that makes a lot of sense indeed!

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


More information about the cfe-commits mailing list