From b7280ac2708e2a36337347de3c27e8fda914683e Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 21 Feb 2017 19:00:35 +0100 Subject: [PATCH] re PR c++/79654 (ICE on invalid c++ code in register_dtor_fn in cp/decl.c:7877) PR c++/79654 * decl.c (cp_finish_decomp): Don't set decl's type to error_mark_node on error. * pt.c (tsubst_decomp_names): Return error_mark_node if the first decl after the decomposition artificial decl has error_mark_node. * decl2.c (prune_vars_needing_no_initialization): Use error_operand_p instead of just == error_mark_node comparison. * g++.dg/cpp1z/decomp26.C: New test. Co-Authored-By: Paolo Carlini From-SVN: r245639 --- gcc/cp/ChangeLog | 11 +++++++++++ gcc/cp/decl.c | 1 - gcc/cp/decl2.c | 2 +- gcc/cp/pt.c | 5 +++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/cpp1z/decomp26.C | 6 ++++++ 6 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/decomp26.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a63eb4be2a5..82225414bf7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,14 @@ +2017-02-21 Jakub Jelinek + Paolo Carlini + + PR c++/79654 + * decl.c (cp_finish_decomp): Don't set decl's type to error_mark_node + on error. + * pt.c (tsubst_decomp_names): Return error_mark_node if the first + decl after the decomposition artificial decl has error_mark_node. + * decl2.c (prune_vars_needing_no_initialization): Use error_operand_p + instead of just == error_mark_node comparison. + 2017-02-21 Jakub Jelinek PR sanitizer/79589 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5ab9a20c829..fa1d645e1ef 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7386,7 +7386,6 @@ 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/decl2.c b/gcc/cp/decl2.c index d2e57ffe917..b50fadf050d 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -3879,7 +3879,7 @@ prune_vars_needing_no_initialization (tree *vars) tree init = TREE_PURPOSE (t); /* Deal gracefully with error. */ - if (decl == error_mark_node) + if (error_operand_p (decl)) { var = &TREE_CHAIN (t); continue; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2cac24f0714..c29e691b44c 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -15610,6 +15610,11 @@ tsubst_decomp_names (tree decl, tree pattern_decl, tree args, && DECL_NAME (decl2); decl2 = DECL_CHAIN (decl2)) { + if (TREE_TYPE (decl2) == error_mark_node && *cnt == 0) + { + gcc_assert (errorcount); + return error_mark_node; + } (*cnt)++; gcc_assert (DECL_HAS_VALUE_EXPR_P (decl2)); tree v = DECL_VALUE_EXPR (decl2); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index abefa2db56a..1262b2eaa79 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-02-21 Jakub Jelinek + PR c++/79654 + * g++.dg/cpp1z/decomp26.C: New test. + PR sanitizer/79589 * g++.dg/ubsan/pr79589.C: New test. diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp26.C b/gcc/testsuite/g++.dg/cpp1z/decomp26.C new file mode 100644 index 00000000000..f413920f545 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp26.C @@ -0,0 +1,6 @@ +// PR c++/79654 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +template T &make(); // { dg-warning "decomposition declaration only available with" "" { target c++14_down } .+1 } +auto [d1, d2] = make(); // { dg-error "cannot decompose non-array non-class type" } -- 2.30.2