From a5e8cbd150d7e7200d54e2e1e125161139e2c7b8 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 6 Feb 2017 21:03:15 +0100 Subject: [PATCH] re PR c++/79372 (ICE on C++ code with illegal decomposition declaration on x86_64-linux-gnu: in tsubst_decomp_names, at cp/pt.c:15599) PR c++/79372 * decl.c (cp_finish_decomp): On error set decl type to error_mark_node. * pt.c (tsubst_expr): Don't call tsubst_decomp_names on decompositions with error_mark_node type. * g++.dg/cpp1z/decomp25.C: New test. From-SVN: r245218 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/decl.c | 1 + gcc/cp/pt.c | 4 +++- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/cpp1z/decomp25.C | 20 ++++++++++++++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/decomp25.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d032028d17c..9889c171b01 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2017-02-06 Jakub Jelinek + + PR c++/79372 + * decl.c (cp_finish_decomp): On error set decl type to error_mark_node. + * pt.c (tsubst_expr): Don't call tsubst_decomp_names on decompositions + with error_mark_node type. + 2017-02-03 Jason Merrill PR c++/78689 - ICE on constructor with label diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 9bdfd4ff64b..d1d485a4fed 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7378,6 +7378,7 @@ cp_finish_decomp (tree decl, tree first, unsigned int count) } first = DECL_CHAIN (first); } + TREE_TYPE (decl) = error_mark_node; if (DECL_P (decl) && DECL_NAMESPACE_SCOPE_P (decl)) SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("")); return; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4c4941a88aa..6072432382d 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -15765,7 +15765,9 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, const_init = (DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (pattern_decl)); cp_finish_decl (decl, init, const_init, NULL_TREE, 0); - if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl)) + if (VAR_P (decl) + && DECL_DECOMPOSITION_P (decl) + && TREE_TYPE (pattern_decl) != error_mark_node) { unsigned int cnt; tree first; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8e9b5fae17c..954851b961d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-02-06 Jakub Jelinek + PR c++/79372 + * g++.dg/cpp1z/decomp25.C: New test. + PR tree-optimization/79284 * gcc.c-torture/compile/pr79284.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp25.C b/gcc/testsuite/g++.dg/cpp1z/decomp25.C new file mode 100644 index 00000000000..c99273613bc --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp25.C @@ -0,0 +1,20 @@ +// PR c++/79372 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +template +struct S +{ + enum E { A }; + void f () { auto [x] = 0; x++; } // { dg-error "cannot decompose non-array non-class type" } + // { dg-warning "decomposition declaration only available with" "" { target c++14_down } .-1 } + void g (T t) { auto [y] = t; y++; } // { dg-error "cannot decompose non-array non-class type" } +}; // { dg-warning "decomposition declaration only available with" "" { target c++14_down } .-1 } + +int +main () +{ + S s; + s.f (); + s.g (5); +} -- 2.30.2