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

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).