https://gcc.gnu.org/g:c7ba34d7014f19adfbe3e64de13d09873b3fc97a

commit r16-5337-gc7ba34d7014f19adfbe3e64de13d09873b3fc97a
Author: Jakub Jelinek <[email protected]>
Date:   Mon Nov 17 15:25:39 2025 +0100

    c++: Add testcase for CWG3045
    
    We already implement expansion statements that way, the following patch
    just adds a testcase for it.
    
    2025-11-17  Jakub Jelinek  <[email protected]>
    
            * g++.dg/DRs/dr3045.C: New test.

Diff:
---
 gcc/testsuite/g++.dg/DRs/dr3045.C | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/gcc/testsuite/g++.dg/DRs/dr3045.C 
b/gcc/testsuite/g++.dg/DRs/dr3045.C
new file mode 100644
index 000000000000..deeb22ca79cf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr3045.C
@@ -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'" }
+  }
+}

Reply via email to