From: Paolo Carlini Date: Tue, 3 Apr 2018 17:53:05 +0000 (+0000) Subject: re PR c++/84768 (ICE with failed class template argument deduction because of invalid... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e52c093a9fd668cddc2397719e8a5449f8cf27de;p=gcc.git re PR c++/84768 (ICE with failed class template argument deduction because of invalid template parameter) /cp 2018-04-03 Paolo Carlini PR c++/84768 * pt.c (rewrite_template_parm): If the first argument is error_mark_node return it immediately. (build_deduction_guide): Check the return value of the latter for error_mark_node. (do_class_deduction): Check the return value of the latter. /testsuite 2018-04-03 Paolo Carlini PR c++/84768 * g++.dg/cpp1z/class-deduction52.C: New. From-SVN: r259049 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8759dc26642..505b2257be2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2018-04-03 Paolo Carlini + + PR c++/84768 + * pt.c (rewrite_template_parm): If the first argument is + error_mark_node return it immediately. + (build_deduction_guide): Check the return value of the + latter for error_mark_node. + (do_class_deduction): Check the return value of the latter. + 2018-04-03 Jason Merrill * semantics.c (finish_if_stmt_cond): Use diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4c0d298cfcc..80670a4826b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -25834,6 +25834,9 @@ static tree rewrite_template_parm (tree olddecl, unsigned index, unsigned level, tree tsubst_args, tsubst_flags_t complain) { + if (olddecl == error_mark_node) + return error_mark_node; + tree oldidx = get_template_parm_index (olddecl); tree newtype; @@ -25969,6 +25972,7 @@ build_deduction_guide (tree ctor, tree outer_args, tsubst_flags_t complain) else { ++processing_template_decl; + bool ok = true; fn_tmpl = (TREE_CODE (ctor) == TEMPLATE_DECL ? ctor @@ -26039,6 +26043,8 @@ build_deduction_guide (tree ctor, tree outer_args, tsubst_flags_t complain) tree olddecl = TREE_VALUE (oldelt); tree newdecl = rewrite_template_parm (olddecl, index, level, tsubst_args, complain); + if (newdecl == error_mark_node) + ok = false; tree newdef = tsubst_template_arg (TREE_PURPOSE (oldelt), tsubst_args, complain, ctor); tree list = build_tree_list (newdef, newdecl); @@ -26060,7 +26066,10 @@ build_deduction_guide (tree ctor, tree outer_args, tsubst_flags_t complain) current_template_parms = save_parms; } + --processing_template_decl; + if (!ok) + return error_mark_node; } if (!memtmpl) @@ -26187,6 +26196,8 @@ do_class_deduction (tree ptype, tree tmpl, tree init, int flags, for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (type)); iter; ++iter) { tree guide = build_deduction_guide (*iter, outer_args, complain); + if (guide == error_mark_node) + return error_mark_node; if ((flags & LOOKUP_ONLYCONVERTING) && DECL_NONCONVERTING_P (STRIP_TEMPLATE (guide))) elided = true; @@ -26238,6 +26249,8 @@ do_class_deduction (tree ptype, tree tmpl, tree init, int flags, if (gtype) { tree guide = build_deduction_guide (gtype, outer_args, complain); + if (guide == error_mark_node) + return error_mark_node; cands = lookup_add (guide, cands); } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 70fd513d469..220fd8f3e8d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-04-03 Paolo Carlini + + PR c++/84768 + * g++.dg/cpp1z/class-deduction52.C: New. + 2018-04-03 Jakub Jelinek PR c++/85147 diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction52.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction52.C new file mode 100644 index 00000000000..db786ce7d62 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction52.C @@ -0,0 +1,11 @@ +// PR c++/84768 +// { dg-additional-options -std=c++17 } + +template struct A {}; + +template struct B +{ + template B(A); // { dg-error "declared" } +}; + +B b = A();