]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Add testcase for CWG3045
authorJakub Jelinek <jakub@redhat.com>
Mon, 17 Nov 2025 14:25:39 +0000 (15:25 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 17 Nov 2025 14:25:39 +0000 (15:25 +0100)
We already implement expansion statements that way, the following patch
just adds a testcase for it.

2025-11-17  Jakub Jelinek  <jakub@redhat.com>

* g++.dg/DRs/dr3045.C: New test.

gcc/testsuite/g++.dg/DRs/dr3045.C [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.dg/DRs/dr3045.C b/gcc/testsuite/g++.dg/DRs/dr3045.C
new file mode 100644 (file)
index 0000000..deeb22c
--- /dev/null
@@ -0,0 +1,16 @@
+// DR 3045 - Regularizing environment interactions of expansion statement
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+void
+foo ()
+{
+  static constexpr int arr[] = { 1, 2, 3 };
+  for (auto g : arr) {                         // { dg-message "'int g' previously declared here" }
+    int g = 42;                                        // { dg-error "redeclaration of 'int g'" }
+  }
+  template for (auto x : arr) {                        // { dg-warning "'template for' only available with" "" { target c++23_down } }
+                                               // { dg-message "'int x' previously declared here" "" { target *-*-* } .-1 }
+    int x = 42;                                        // { dg-error "redeclaration of 'int x'" }
+  }
+}