public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98423] New: The defaulted default constructor defined as deleted when one of variant member has a default member initializer
@ 2020-12-23 2:47 xmh970252187 at gmail dot com
2020-12-28 11:58 ` [Bug c++/98423] " jakub at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: xmh970252187 at gmail dot com @ 2020-12-23 2:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98423
Bug ID: 98423
Summary: The defaulted default constructor defined as deleted
when one of variant member has a default member
initializer
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: xmh970252187 at gmail dot com
Target Milestone: ---
struct A{
A(){}
};
union C{
A a;
int b = 0;
};
int main(){
C c;
}
GCC reports the default constructor for union `C` is defined as
deleted. However, the relevant rule in the current c++ standard says
that:
> A defaulted default constructor for class X is defined as deleted if:
>> X is a union that has a variant member with a non-trivial default constructor and no variant member of X has a default member initializer,
>> X is a non-union class that has a variant member M with a non-trivial default constructor and no variant member of the anonymous union containing M has a default member initializer
In simple, as long as one of these variant members has a default
member initializer, then the default constructor for the containing
class will not be defined as deleted. In this example, the variant
member `b` has a default member initializer, hence `C::C()` should be
defined rather than deleted. Is it a bug?
GCC only agrees this code is supported:
struct A{
A(){}
};
union C{
A a{};
int b;
};
int main(){
C c;
}
If it is the right behavior, then the relevant rule should be described as:
> X is a union that has a variant member with a non-trivial default constructor and no default member initializer is supplied for the variant member.
However, the rule does not say this.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/98423] The defaulted default constructor defined as deleted when one of variant member has a default member initializer
2020-12-23 2:47 [Bug c++/98423] New: The defaulted default constructor defined as deleted when one of variant member has a default member initializer xmh970252187 at gmail dot com
@ 2020-12-28 11:58 ` jakub at gcc dot gnu.org
2020-12-28 11:59 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-12-28 11:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98423
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org,
| |jason at gcc dot gnu.org,
| |mpolacek at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think it isn't solely about the process_subob_fn
if (TREE_CODE (arg) == FIELD_DECL
&& TREE_CODE (DECL_CONTEXT (arg)) == UNION_TYPE)
{
if (deleted_p)
*deleted_p = true;
if (diag)
error ("union member %q+D with non-trivial %qD", arg, fn);
}
diagnostics that probably shouldn't be performed if the union type has nsdmi on
any member, isn't it also the:
if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn))
{
*constexpr_p = false;
if (diag)
{
inform (DECL_SOURCE_LOCATION (fn),
SFK_DTOR_P (sfk)
? G_("defaulted destructor calls non-%<constexpr%> %qD")
: G_("defaulted constructor calls non-%<constexpr%> %qD"),
fn);
explain_invalid_constexpr_fn (fn);
}
}
diagnostics (why would a default constructor of a union be non-constexpr just
because some variant member without nsdmi has non-constexpr default
constructor), perhaps the spec_p stuff too.
So for UNION_TYPE we probably want to search for nsdmis in another loop at the
start of walk_field_subobs and punt some tests for some special members if
there are any nsdmis.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/98423] The defaulted default constructor defined as deleted when one of variant member has a default member initializer
2020-12-23 2:47 [Bug c++/98423] New: The defaulted default constructor defined as deleted when one of variant member has a default member initializer xmh970252187 at gmail dot com
2020-12-28 11:58 ` [Bug c++/98423] " jakub at gcc dot gnu.org
@ 2020-12-28 11:59 ` jakub at gcc dot gnu.org
2022-07-20 22:14 ` jason at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-12-28 11:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98423
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
It is CWG2084 btw.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/98423] The defaulted default constructor defined as deleted when one of variant member has a default member initializer
2020-12-23 2:47 [Bug c++/98423] New: The defaulted default constructor defined as deleted when one of variant member has a default member initializer xmh970252187 at gmail dot com
2020-12-28 11:58 ` [Bug c++/98423] " jakub at gcc dot gnu.org
2020-12-28 11:59 ` jakub at gcc dot gnu.org
@ 2022-07-20 22:14 ` jason at gcc dot gnu.org
2022-07-22 5:43 ` jason at gcc dot gnu.org
2022-07-22 7:23 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2022-07-20 22:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98423
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2022-07-20
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/98423] The defaulted default constructor defined as deleted when one of variant member has a default member initializer
2020-12-23 2:47 [Bug c++/98423] New: The defaulted default constructor defined as deleted when one of variant member has a default member initializer xmh970252187 at gmail dot com
` (2 preceding siblings ...)
2022-07-20 22:14 ` jason at gcc dot gnu.org
@ 2022-07-22 5:43 ` jason at gcc dot gnu.org
2022-07-22 7:23 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2022-07-22 5:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98423
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Target Milestone|--- |13.0
Resolution|--- |FIXED
--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 13, I mistakenly put PR 94823 in the ChangeLog instead of this
one.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/98423] The defaulted default constructor defined as deleted when one of variant member has a default member initializer
2020-12-23 2:47 [Bug c++/98423] New: The defaulted default constructor defined as deleted when one of variant member has a default member initializer xmh970252187 at gmail dot com
` (3 preceding siblings ...)
2022-07-22 5:43 ` jason at gcc dot gnu.org
@ 2022-07-22 7:23 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2022-07-22 7:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98423
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jens.maurer at gmx dot net
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 106150 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-07-22 7:23 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-23 2:47 [Bug c++/98423] New: The defaulted default constructor defined as deleted when one of variant member has a default member initializer xmh970252187 at gmail dot com
2020-12-28 11:58 ` [Bug c++/98423] " jakub at gcc dot gnu.org
2020-12-28 11:59 ` jakub at gcc dot gnu.org
2022-07-20 22:14 ` jason at gcc dot gnu.org
2022-07-22 5:43 ` jason at gcc dot gnu.org
2022-07-22 7:23 ` redi at gcc dot gnu.org
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).