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.
This commit is contained in:
Marek Polacek 2021-01-13 13:12:14 -05:00
parent eed40bca6f
commit 2b27f37f90
2 changed files with 26 additions and 4 deletions

View file

@ -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;

View file

@ -0,0 +1,21 @@
// PR c++/98659
// { dg-do compile }
template <bool> struct enable_if;
struct function {
template <typename _F> void operator=(_F);
};
struct map {
function operator[](int);
};
enum { E };
template <typename> void foo ();
template <typename T>
typename enable_if<T::value>::type foo ();
void
bar ()
{
map m;
m[E] = foo<int>;
}