public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: ICE with noexcept and local specialization [PR114114]
@ 2024-03-05 20:56 Marek Polacek
  2024-03-05 23:20 ` Jason Merrill
  2024-03-15 14:35 ` Patrick Palka
  0 siblings, 2 replies; 6+ messages in thread
From: Marek Polacek @ 2024-03-05 20:56 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

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

-- >8 --
Here we ICE because we call register_local_specialization while
local_specializations is null, so

  local_specializations->put ();

crashes on null this.  It's null since maybe_instantiate_noexcept calls
push_to_top_level which creates a new scope.  Normally, I would have
guessed that we need a new local_specialization_stack.  But here we're
dealing with an operand of a noexcept, which is an unevaluated operand,
and those aren't registered in the hash map.  maybe_instantiate_noexcept
wasn't signalling that it's substituting an unevaluated operand though.

	PR c++/114114

gcc/cp/ChangeLog:

	* pt.cc (maybe_instantiate_noexcept): Save/restore
	cp_unevaluated_operand, c_inhibit_evaluation_warnings, and
	cp_noexcept_operand around the tsubst_expr call.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/noexcept84.C: New test.
---
 gcc/cp/pt.cc                            |  6 +++++
 gcc/testsuite/g++.dg/cpp0x/noexcept84.C | 32 +++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept84.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index c4bc54a8fdb..11f7d33c766 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -26869,10 +26869,16 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain)
 	  if (orig_fn)
 	    ++processing_template_decl;
 
+	  ++cp_unevaluated_operand;
+	  ++c_inhibit_evaluation_warnings;
+	  ++cp_noexcept_operand;
 	  /* Do deferred instantiation of the noexcept-specifier.  */
 	  noex = tsubst_expr (DEFERRED_NOEXCEPT_PATTERN (noex),
 			      DEFERRED_NOEXCEPT_ARGS (noex),
 			      tf_warning_or_error, fn);
+	  --cp_unevaluated_operand;
+	  --c_inhibit_evaluation_warnings;
+	  --cp_noexcept_operand;
 
 	  /* Build up the noexcept-specification.  */
 	  spec = build_noexcept_spec (noex, tf_warning_or_error);
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept84.C b/gcc/testsuite/g++.dg/cpp0x/noexcept84.C
new file mode 100644
index 00000000000..06f33264f77
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept84.C
@@ -0,0 +1,32 @@
+// PR c++/114114
+// { dg-do compile { target c++11 } }
+
+template<bool B>
+constexpr void
+test ()
+{
+  constexpr bool is_yes = B;
+  struct S {
+    constexpr S() noexcept(is_yes) { }
+  };
+  S s;
+}
+
+constexpr bool foo() { return true; }
+
+template<typename T>
+constexpr void
+test2 ()
+{
+  constexpr T (*pfn)() = &foo;
+  struct S {
+    constexpr S() noexcept(pfn()) { }
+  };
+  S s;
+}
+
+int main()
+{
+  test<true>();
+  test2<bool>();
+}

base-commit: 8776468d9e57ace5f832c1368243a6dbce9984d5
-- 
2.44.0


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

end of thread, other threads:[~2024-03-21 21:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-05 20:56 [PATCH] c++: ICE with noexcept and local specialization [PR114114] Marek Polacek
2024-03-05 23:20 ` Jason Merrill
2024-03-15 14:35 ` Patrick Palka
2024-03-15 15:23   ` Marek Polacek
2024-03-15 16:12     ` Patrick Palka
2024-03-21 21:04       ` 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).