From: Paolo Carlini Date: Mon, 1 Apr 2019 17:09:47 +0000 (+0000) Subject: re PR c++/62207 (ICE: tree check: expected tree that contains 'decl minimal' structur... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5ed22cbbfce94c6fca8e4247a74315aacb759918;p=gcc.git re PR c++/62207 (ICE: tree check: expected tree that contains 'decl minimal' structure, have 'overload' in tsubst_copy, at cp/pt.c) /cp 2019-04-01 Paolo Carlini PR c++/62207 * pt.c (tsubst_copy): Deal with lookup_name not returing a variable. /testsuite 2019-04-01 Paolo Carlini PR c++/62207 * g++.dg/template/crash130.C: New. * g++.dg/template/crash131.C: Likewise. From-SVN: r270064 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8c6e9931db1..3501f6b8cf3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-04-01 Paolo Carlini + + PR c++/62207 + * pt.c (tsubst_copy): Deal with lookup_name not returing a variable. + 2019-03-31 Marek Polacek PR c++/89852 - ICE with C++11 functional cast with { }. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index f3faa89f671..d5249a095c6 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -15591,12 +15591,23 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) { /* First try name lookup to find the instantiation. */ r = lookup_name (DECL_NAME (t)); - if (r && !is_capture_proxy (r)) + if (r) { - /* Make sure that the one we found is the one we want. */ - tree ctx = enclosing_instantiation_of (DECL_CONTEXT (t)); - if (ctx != DECL_CONTEXT (r)) - r = NULL_TREE; + if (!VAR_P (r)) + { + /* During error-recovery we may find a non-variable, + even an OVERLOAD: just bail out and avoid ICEs and + duplicate diagnostics (c++/62207). */ + gcc_assert (seen_error ()); + return error_mark_node; + } + if (!is_capture_proxy (r)) + { + /* Make sure the one we found is the one we want. */ + tree ctx = enclosing_instantiation_of (DECL_CONTEXT (t)); + if (ctx != DECL_CONTEXT (r)) + r = NULL_TREE; + } } if (r) @@ -15632,7 +15643,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) } gcc_assert (cp_unevaluated_operand || TREE_STATIC (r) || decl_constant_var_p (r) - || errorcount || sorrycount); + || seen_error ()); if (!processing_template_decl && !TREE_STATIC (r)) r = process_outer_var_ref (r, complain); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1c516a95185..244ae87b495 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-04-01 Paolo Carlini + + PR c++/62207 + * g++.dg/template/crash130.C: New. + * g++.dg/template/crash131.C: Likewise. + 2019-04-01 Martin Sebor PR c/89685 diff --git a/gcc/testsuite/g++.dg/template/crash130.C b/gcc/testsuite/g++.dg/template/crash130.C new file mode 100644 index 00000000000..c3e154f0e2b --- /dev/null +++ b/gcc/testsuite/g++.dg/template/crash130.C @@ -0,0 +1,15 @@ +// PR c++/62207 + +template void foo(T) +{ + X; // { dg-error "not declared" } + X; +} + +void X(); +void X(int); + +void bar() +{ + foo(0); +} diff --git a/gcc/testsuite/g++.dg/template/crash131.C b/gcc/testsuite/g++.dg/template/crash131.C new file mode 100644 index 00000000000..7b3a47dce02 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/crash131.C @@ -0,0 +1,16 @@ +// PR c++/62207 + +template +class X { +public: + template class Y {}; + template void y() {} + X(F f) + { + Y y; // { dg-error "not a constant" } + + y.value(); + } +}; + +int main() { X x(1); }