From: Jakub Jelinek Date: Mon, 17 Nov 2025 14:25:39 +0000 (+0100) Subject: c++: Add testcase for CWG3045 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7ba34d7014f19adfbe3e64de13d09873b3fc97a;p=thirdparty%2Fgcc.git 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 * g++.dg/DRs/dr3045.C: New test. --- diff --git a/gcc/testsuite/g++.dg/DRs/dr3045.C b/gcc/testsuite/g++.dg/DRs/dr3045.C new file mode 100644 index 00000000000..deeb22ca79c --- /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'" } + } +}