aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2025-08-11 08:53:26 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2025-08-11 09:05:20 +0200
commitaf31db6461110dfb81efaf2a287327226ae5a7a8 (patch)
tree6c1477e5b0a9206fac2c2591960dec469d3beb7e
parente5bb3896036add7416707512e3d440055cffdf16 (diff)
downloadgcc-af31db6461110dfb81efaf2a287327226ae5a7a8.zip
gcc-af31db6461110dfb81efaf2a287327226ae5a7a8.tar.gz
gcc-af31db6461110dfb81efaf2a287327226ae5a7a8.tar.bz2
c++: Fix structured binding redeclaration error recovery [PR121442]
My C++26 P2686R4 PR117784 caused ICE on the following testcase. While the earlier conditions guarantee decl2 is not error_mark_node, decl can be (that is used when something erroneous has been seen earlier and the whole structured bindings will be ignored after parsing). So, the following patch avoids the copying of constexpr/constinit flags if decl is error_mark_node. 2025-08-11 Jakub Jelinek <jakub@redhat.com> PR c++/121442 * parser.cc (cp_parser_decomposition_declaration): Don't copy DECL_DECLARED_CONST{EXPR,INIT}_P bits from decl to decl2 if decl is error_mark_node. * g++.dg/cpp1z/decomp65.C: New test.
-rw-r--r--gcc/cp/parser.cc9
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/decomp65.C13
2 files changed, 20 insertions, 2 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 743fd74..1dbe35b 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -17002,8 +17002,13 @@ cp_parser_decomposition_declaration (cp_parser *parser,
else
{
prev = decl2;
- DECL_DECLARED_CONSTEXPR_P (decl2) = DECL_DECLARED_CONSTEXPR_P (decl);
- DECL_DECLARED_CONSTINIT_P (decl2) = DECL_DECLARED_CONSTINIT_P (decl);
+ if (decl != error_mark_node)
+ {
+ DECL_DECLARED_CONSTEXPR_P (decl2)
+ = DECL_DECLARED_CONSTEXPR_P (decl);
+ DECL_DECLARED_CONSTINIT_P (decl2)
+ = DECL_DECLARED_CONSTINIT_P (decl);
+ }
if (j == (unsigned) pack)
{
tree dtype = cxx_make_type (DECLTYPE_TYPE);
diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp65.C b/gcc/testsuite/g++.dg/cpp1z/decomp65.C
new file mode 100644
index 0000000..5dd8eff
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/decomp65.C
@@ -0,0 +1,13 @@
+// PR c++/121442
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+struct S { int a, b, c, d, e; };
+
+void
+foo ()
+{
+ auto [a, b, b, b, c ] = S {}; // { dg-warning "structured bindings only available with" "" { target c++14_down } }
+ // { dg-error "redeclaration of 'auto b'" "" { target *-*-* } .-1 }
+ // { dg-message "'auto b' previously declared here" "" { target *-*-* } .-2 }
+}