From 2b27f37f90cb66e277b734c605639e2f00a2e942 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 13 Jan 2021 13:12:14 -0500 Subject: [PATCH] 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. --- gcc/cp/pt.c | 9 +++++---- gcc/testsuite/g++.dg/template/deduce8.C | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/deduce8.C 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; +} -- 2.30.2