Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Jan 10, 2022

[class.copy.ctor] p10 states that

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.

@frederick-vs-ja
Copy link
Contributor

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.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Jan 11, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants