public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Crash when deducing template arguments [PR98659]
@ 2021-01-13 18:38 Marek Polacek
  2021-01-19 20:41 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2021-01-13 18:38 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

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.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

gcc/cp/ChangeLog:

	PR c++/98659
	* pt.c (resolve_overloaded_unification): Don't call
	maybe_instantiate_noexcept with error_mark_node.

gcc/testsuite/ChangeLog:

	PR c++/98659
	* g++.dg/template/deduce8.C: New test.
---
 gcc/cp/pt.c                             |  2 +-
 gcc/testsuite/g++.dg/template/deduce8.C | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/template/deduce8.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 100c35f053c..83ecb0a2c3a 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -22382,7 +22382,7 @@ resolve_overloaded_unification (tree tparms,
 		  --function_depth;
 		}
 
-	      if (flag_noexcept_type)
+	      if (flag_noexcept_type && fn != error_mark_node)
 		maybe_instantiate_noexcept (fn, tf_none);
 
 	      elem = TREE_TYPE (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>;
+}

base-commit: 7d7ef413ef1b696dec2710ae0acc058bdc832686
-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-19 21:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13 18:38 [PATCH] c++: Crash when deducing template arguments [PR98659] Marek Polacek
2021-01-19 20:41 ` Jason Merrill
2021-01-19 21:09   ` [PATCH v2] " Marek Polacek
2021-01-19 21:12     ` Jason Merrill

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).