public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-3387] c++: Fix up constexpr evaluation of deleting dtors [PR100495] Date: Tue, 7 Sep 2021 17:35:22 +0000 (GMT) [thread overview] Message-ID: <20210907173522.792BA385843B@sourceware.org> (raw) https://gcc.gnu.org/g:81f9718139cb1cc164ada411ada8cca9f32b8be8 commit r12-3387-g81f9718139cb1cc164ada411ada8cca9f32b8be8 Author: Jakub Jelinek <jakub@redhat.com> Date: Tue Sep 7 19:33:28 2021 +0200 c++: Fix up constexpr evaluation of deleting dtors [PR100495] We do not save bodies of constexpr clones and instead evaluate the bodies of the constexpr functions they were cloned from. I believe that is just fine for constructors because complete vs. base ctors differ only in classes that have virtual bases and such constructors aren't constexpr, similarly complete/base destructors. But as the testcase below shows, for deleting destructors it is not fine, deleting dtors while marked as clones in fact are just artificial functions with synthetized body which calls the user destructor and deallocation. So, either we'd need to evaluate the destructor and afterwards synthetize and evaluate the deallocation, or we can just save and use the deleting dtors bodies. The latter seems much easier to me. 2021-09-07 Jakub Jelinek <jakub@redhat.com> PR c++/100495 * constexpr.c (maybe_save_constexpr_fundef): Save body even for constexpr deleting dtors. (cxx_eval_call_expression): Don't use DECL_CLONED_FUNCTION for deleting dtors. * g++.dg/cpp2a/constexpr-new21.C: New test. Diff: --- gcc/cp/constexpr.c | 4 ++-- gcc/testsuite/g++.dg/cpp2a/constexpr-new21.C | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 45adbab485a..7772fe62d95 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -865,7 +865,7 @@ maybe_save_constexpr_fundef (tree fun) if (processing_template_decl || !DECL_DECLARED_CONSTEXPR_P (fun) || cp_function_chain->invalid_constexpr - || DECL_CLONED_FUNCTION_P (fun)) + || (DECL_CLONED_FUNCTION_P (fun) && !DECL_DELETING_DESTRUCTOR_P (fun))) return; if (!is_valid_constexpr_fn (fun, !DECL_GENERATED_P (fun))) @@ -2372,7 +2372,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, *non_constant_p = true; return t; } - if (DECL_CLONED_FUNCTION_P (fun)) + if (DECL_CLONED_FUNCTION_P (fun) && !DECL_DELETING_DESTRUCTOR_P (fun)) fun = DECL_CLONED_FUNCTION (fun); if (is_ubsan_builtin_p (fun)) diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-new21.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-new21.C new file mode 100644 index 00000000000..8231e992483 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-new21.C @@ -0,0 +1,17 @@ +// PR c++/100495 +// { dg-do compile { target c++20 } } + +struct S { + constexpr virtual ~S () {} +}; + +constexpr bool +foo () +{ + S *p = new S (); + delete p; + return true; +} + +constexpr bool x = foo (); +static_assert (x);
reply other threads:[~2021-09-07 17:35 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210907173522.792BA385843B@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).