c++: Fix ICE with defaulted destructor and template.
authorJason Merrill <jason@redhat.com>
Thu, 23 Jan 2020 17:32:02 +0000 (12:32 -0500)
committerJason Merrill <jason@redhat.com>
Thu, 23 Jan 2020 18:11:10 +0000 (13:11 -0500)
In a template we don't instantiate a deferred noexcept-spec, and we don't
need it because we aren't going to do anything with the value of
throwing_cleanup in a template anyway.

PR c++/93345 - ICE with defaulted dtor and template.
PR c++/33799
* decl.c (cxx_maybe_build_cleanup): Don't try to set
throwing_cleanup in a template.

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/cpp0x/initlist-cleanup1.C [new file with mode: 0644]

index 47d4f2d496cb860a23f6aa3b341ef9e2fac2d6e6..f99951cb72c550579a2c49d95314f0de4024986f 100644 (file)
@@ -1,3 +1,10 @@
+2020-01-23  Jason Merrill  <jason@redhat.com>
+
+       PR c++/93345 - ICE with defaulted dtor and template.
+       PR c++/33799
+       * decl.c (cxx_maybe_build_cleanup): Don't try to set
+       throwing_cleanup in a template.
+
 2020-01-22  Marek Polacek  <polacek@redhat.com>
 
        PR c++/92907 - noexcept does not consider "const" in member functions.
index 47ff7eea88f1ebe42eeac7b6cc9ad51c8cf11f2a..98ed79f3579e6aeff744cf1dc41b128921777a36 100644 (file)
@@ -17393,7 +17393,8 @@ cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
       && !mark_used (decl, complain) && !(complain & tf_error))
     return error_mark_node;
 
-  if (cleanup && cfun && !expr_noexcept_p (cleanup, tf_none))
+  if (cleanup && cfun && !processing_template_decl
+      && !expr_noexcept_p (cleanup, tf_none))
     cp_function_chain->throwing_cleanup = true;
 
   return cleanup;
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-cleanup1.C b/gcc/testsuite/g++.dg/cpp0x/initlist-cleanup1.C
new file mode 100644 (file)
index 0000000..1e3ac12
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/93345
+// { dg-do compile { target c++11 } }
+
+struct ln {
+  ~ln ();
+};
+
+struct ry {
+  ln kj;
+};
+
+template<typename GC>
+void
+dz ()
+{
+  ry{};
+}