From: Marek Polacek Date: Wed, 13 Jan 2021 18:12:14 +0000 (-0500) Subject: c++: Crash when deducing template arguments [PR98659] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2b27f37f90cb66e277b734c605639e2f00a2e942;p=gcc.git c++: Crash when deducing template arguments [PR98659] maybe_instantiate_noexcept doesn't expect to see error_mark_node, but the new callsite I introduced in r11-6476 can pass error_mark_node to it. So cope. gcc/cp/ChangeLog: PR c++/98659 * pt.c (maybe_instantiate_noexcept): Return false if FN is error_mark_node. gcc/testsuite/ChangeLog: PR c++/98659 * g++.dg/template/deduce8.C: New test. --- diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 12d084031b1..c9f5811980e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -25457,7 +25457,8 @@ always_instantiate_p (tree decl) bool maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) { - tree fntype, spec, noex; + if (fn == error_mark_node) + return false; /* Don't instantiate a noexcept-specification from template context. */ if (processing_template_decl @@ -25476,13 +25477,13 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) return !DECL_MAYBE_DELETED (fn); } - fntype = TREE_TYPE (fn); - spec = TYPE_RAISES_EXCEPTIONS (fntype); + tree fntype = TREE_TYPE (fn); + tree spec = TYPE_RAISES_EXCEPTIONS (fntype); if (!spec || !TREE_PURPOSE (spec)) return true; - noex = TREE_PURPOSE (spec); + tree noex = TREE_PURPOSE (spec); if (TREE_CODE (noex) != DEFERRED_NOEXCEPT && TREE_CODE (noex) != DEFERRED_PARSE) return true; diff --git a/gcc/testsuite/g++.dg/template/deduce8.C b/gcc/testsuite/g++.dg/template/deduce8.C new file mode 100644 index 00000000000..430be426689 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/deduce8.C @@ -0,0 +1,21 @@ +// PR c++/98659 +// { dg-do compile } + +template struct enable_if; +struct function { + template void operator=(_F); +}; +struct map { + function operator[](int); +}; +enum { E }; +template void foo (); +template +typename enable_if::type foo (); + +void +bar () +{ + map m; + m[E] = foo; +}