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 r12-3555] c++: default ctor that's also a list ctor [PR102050] Date: Wed, 15 Sep 2021 17:56:12 +0000 (GMT) [thread overview] Message-ID: <20210915175612.1F6CE3857815@sourceware.org> (raw) https://gcc.gnu.org/g:2ab5c3d5457f0d480c6423ee7ac52ce1f98592c9 commit r12-3555-g2ab5c3d5457f0d480c6423ee7ac52ce1f98592c9 Author: Patrick Palka <ppalka@redhat.com> Date: Wed Sep 15 13:54:53 2021 -0400 c++: default ctor that's also a list ctor [PR102050] In grok_special_member_properties we need to set TYPE_HAS_COPY_CTOR, TYPE_HAS_DEFAULT_CONSTRUCTOR and TYPE_HAS_LIST_CTOR independently from each other because a constructor can be both a default and list constructor (as in the first testcase), or both a default and copy constructor (as in the second testcase). PR c++/102050 gcc/cp/ChangeLog: * decl.c (grok_special_member_properties): Set TYPE_HAS_COPY_CTOR, TYPE_HAS_DEFAULT_CONSTRUCTOR and TYPE_HAS_LIST_CTOR independently from each other. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist125.C: New test. * g++.dg/cpp0x/initlist126.C: New test. Diff: --- gcc/cp/decl.c | 6 ++++-- gcc/testsuite/g++.dg/cpp0x/initlist125.C | 12 ++++++++++++ gcc/testsuite/g++.dg/cpp0x/initlist126.C | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 9ad9446e262..c0f1496636f 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -14847,9 +14847,11 @@ grok_special_member_properties (tree decl) if (ctor > 1) TYPE_HAS_CONST_COPY_CTOR (class_type) = 1; } - else if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl))) + + if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl))) TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1; - else if (is_list_ctor (decl)) + + if (is_list_ctor (decl)) TYPE_HAS_LIST_CTOR (class_type) = 1; if (DECL_DECLARED_CONSTEXPR_P (decl) diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist125.C b/gcc/testsuite/g++.dg/cpp0x/initlist125.C new file mode 100644 index 00000000000..49dee1c0ccd --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist125.C @@ -0,0 +1,12 @@ +// PR c++/102050 +// { dg-do compile { target c++11 } } + +#include <initializer_list> + +struct A { + A(std::initializer_list<int> = {}); +}; + +A x{0}; +A y{1, 2, 3}; +A z; diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist126.C b/gcc/testsuite/g++.dg/cpp0x/initlist126.C new file mode 100644 index 00000000000..0a8fb998be6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist126.C @@ -0,0 +1,17 @@ +// PR c++/102050 +// { dg-do compile { target c++11 } } + +#include <initializer_list> + +extern struct A a; + +struct A { + A(const A& = a); + A(std::initializer_list<int>) = delete; +}; + +void f(A); + +int main() { + f({}); // { dg-bogus "deleted" } +}
reply other threads:[~2021-09-15 17:56 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=20210915175612.1F6CE3857815@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).