public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10716] c++: cxx_eval_array_reference and empty elem type [PR101194] Date: Wed, 11 May 2022 17:25:06 +0000 (GMT) [thread overview] Message-ID: <20220511172506.4A49F3858016@sourceware.org> (raw) https://gcc.gnu.org/g:5fcedef529c7564b6485ab2893c08865798a66ec commit r10-10716-g5fcedef529c7564b6485ab2893c08865798a66ec Author: Patrick Palka <ppalka@redhat.com> Date: Wed Jun 30 20:44:52 2021 -0400 c++: cxx_eval_array_reference and empty elem type [PR101194] Here the initializer for x is represented as an empty CONSTRUCTOR due to its empty element type. So during constexpr evaluation of the ARRAY_REF x[0], we end up trying to value initialize the omitted element at index 0, which fails because the element type is not default constructible. This patch makes cxx_eval_array_reference specifically handle the case where the element type is an empty type. PR c++/101194 gcc/cp/ChangeLog: * constexpr.c (cxx_eval_array_reference): When the element type is an empty type and the corresponding element is omitted, just return an empty CONSTRUCTOR instead of attempting value initialization. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-empty16.C: New test. (cherry picked from commit a688c284dd3848b6c4ea553035f0f9769fb4fbc9) Diff: --- gcc/cp/constexpr.c | 4 +++- gcc/testsuite/g++.dg/cpp0x/constexpr-empty16.C | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index dd0e955ed7b..28b0a88a658 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -3637,7 +3637,9 @@ cxx_eval_array_reference (const constexpr_ctx *ctx, tree t, directly for non-aggregates to avoid creating a garbage CONSTRUCTOR. */ tree val; constexpr_ctx new_ctx; - if (CP_AGGREGATE_TYPE_P (elem_type)) + if (is_really_empty_class (elem_type, /*ignore_vptr*/false)) + return build_constructor (elem_type, NULL); + else if (CP_AGGREGATE_TYPE_P (elem_type)) { tree empty_ctor = build_constructor (init_list_type_node, NULL); val = digest_init (elem_type, empty_ctor, tf_warning_or_error); diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-empty16.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-empty16.C new file mode 100644 index 00000000000..79be244a1d0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-empty16.C @@ -0,0 +1,10 @@ +// PR c++/101194 +// { dg-do compile { target c++11 } } + +struct nodefault { + constexpr nodefault(int) { } +}; + +constexpr nodefault x[1] = { nodefault{0} }; + +constexpr nodefault y = x[0];
reply other threads:[~2022-05-11 17:25 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=20220511172506.4A49F3858016@sourceware.org \ --to=ppalka@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).