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; +}