On Tue, Jan 19, 2021 at 03:41:57PM -0500, Jason Merrill wrote:
> On 1/13/21 1:38 PM, Marek Polacek wrote:
> > maybe_instantiate_noexcept doesn't expect to see error_mark_node, so
> > the new callsite I introduced in r11-6476 needs to be properly guarded.
> 
> I'd rather fix maybe_instantiate_noexcept to deal with error_mark_node.

Ok, here's v2.  I've checked all maybe_instantiate_noexcept calls to see
if they don't need to be guarded by != error_mark_node anymore but found
none.

Ok for trunk if the usual testing passes?

-- >8 --
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 957140115e4..aa7a155815a 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -25456,7 +25456,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
@@ -25475,13 +25476,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 <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>;
+}

base-commit: c37f1d4081f5a19e39192d13e2a3acea13662e5a
-- 
2.29.2

Reply via email to