aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2021-01-13 13:12:14 -0500
committerMarek Polacek <polacek@redhat.com>2021-01-19 17:41:20 -0500
commit2b27f37f90cb66e277b734c605639e2f00a2e942 (patch)
treede1eff1485fbf3909983e47a81a2bcc59cacfb64
parenteed40bca6f2eb3af0c811cf6ec9e123c5bf4907d (diff)
downloadgcc-2b27f37f90cb66e277b734c605639e2f00a2e942.zip
gcc-2b27f37f90cb66e277b734c605639e2f00a2e942.tar.gz
gcc-2b27f37f90cb66e277b734c605639e2f00a2e942.tar.bz2
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.
-rw-r--r--gcc/cp/pt.c9
-rw-r--r--gcc/testsuite/g++.dg/template/deduce8.C21
2 files changed, 26 insertions, 4 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 12d0840..c9f5811 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 0000000..430be42
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/deduce8.C
@@ -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>;
+}