public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-9288] c++: Crash when deducing template arguments [PR98790]
@ 2021-01-22 17:56 Marek Polacek
  0 siblings, 0 replies; only message in thread
From: Marek Polacek @ 2021-01-22 17:56 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:c806314b32987096d79de21e72dc0cf783e51d57

commit r10-9288-gc806314b32987096d79de21e72dc0cf783e51d57
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Jan 22 12:50:53 2021 -0500

    c++: Crash when deducing template arguments [PR98790]
    
    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++/98790
            * pt.c (maybe_instantiate_noexcept): Return false if FN is
            error_mark_node.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/98790
            * g++.dg/template/deduce8.C: New test.

Diff:
---
 gcc/cp/pt.c                             |  3 +++
 gcc/testsuite/g++.dg/template/deduce8.C | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index dc2e032d6dd..abef0cdc663 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -25323,6 +25323,9 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain)
 {
   tree fntype, spec, noex, clone;
 
+  if (fn == error_mark_node)
+    return false;
+
   /* Don't instantiate a noexcept-specification from template context.  */
   if (processing_template_decl
       && (!flag_noexcept_type || type_dependent_expression_p (fn)))
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>;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-22 17:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-22 17:56 [gcc r10-9288] c++: Crash when deducing template arguments [PR98790] Marek Polacek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).