You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[class.copy.ctor] p10 What is the selected one by overload resolution for a variant member in the context of implicitly copy/move constructor for a union?
#5194
Open
xmh0511 opened this issue
Jan 10, 2022
· 2 comments
An implicitly-declared copy/move constructor is an inline public member of its class. A defaulted copy/move constructor for a class X is defined as deleted ([dcl.fct.def.delete]) if X has:
[...]
a variant member whose corresponding constructor as selected by overload resolution is non-trivial,
Since in [class.copy.ctor] p15, we have said that
The implicitly-defined copy/move constructor for a union X copies the object representation ([basic.types]) of X.
According to [basic.types.general] p4
The object representation of an object of type T is the sequence of N unsigned char objects taken up by the object of type T, where N equals sizeof(T).
Hence, copying the object representation of X means that copies the sequence of N unsigned char objects taken up by the object of type X, where N equals sizeof(X). So, there is no overload resolution here since we didn't invoke any constructor(function). This is a contradictory point. Should we say that?
a variant member whose corresponding constructor, as selected by overload resolution as if the variant member is copy-initialized from the corresponding source
As if the overload resolution can occur in this context to determine the constructor for the variant member.
The text was updated successfully, but these errors were encountered:
I think the main problem is that the overload resolution is not clearly specified, because the sources of initialization are specified in [class.copy.ctor] p14, which only covers non-union classes.
IMO we can clarify the overload resolution by adding this to [class.copy.ctor] (10.2):
, where the overload resolution is performed as if the class of the member is not a union,
It might be better to separate the "sources of initialization" portion from [class.copy.ctor] p14.
Why do you choose "copy-initialized"? Only "direct-initialized" is used in [class.copy.ctor] p14.
@frederick-vs-ja Alright, I misused "copy-initialized". It should be "direct-initialized", in the manner as [class.copy.ctor] p14 did. I think this revision would be more clear:
a variant member whose corresponding constructor, as selected by overload resolution where the overload resolution is performed as if the class of which the variant is a member is a non-union class.
[class.copy.ctor] p10 states that
Since in [class.copy.ctor] p15, we have said that
According to [basic.types.general] p4
Hence, copying the object representation of X means that copies the sequence of N unsigned char objects taken up by the object of type X, where N equals sizeof(X). So, there is no overload resolution here since we didn't invoke any constructor(function). This is a contradictory point. Should we say that?
As if the overload resolution can occur in this context to determine the constructor for the variant member.
The text was updated successfully, but these errors were encountered: