From 20afdcd36982752ba012960b862e9be7154b1274 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 23 Jan 2020 12:32:02 -0500 Subject: [PATCH] c++: Fix ICE with defaulted destructor and template. 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 | 7 +++++++ gcc/cp/decl.c | 3 ++- gcc/testsuite/g++.dg/cpp0x/initlist-cleanup1.C | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-cleanup1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 47d4f2d496c..f99951cb72c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2020-01-23 Jason Merrill + + 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 PR c++/92907 - noexcept does not consider "const" in member functions. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 47ff7eea88f..98ed79f3579 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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 index 00000000000..1e3ac122480 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-cleanup1.C @@ -0,0 +1,17 @@ +// PR c++/93345 +// { dg-do compile { target c++11 } } + +struct ln { + ~ln (); +}; + +struct ry { + ln kj; +}; + +template +void +dz () +{ + ry{}; +} -- 2.30.2