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

[over.match.ctor] Initialization by "()" neither is copy-initialization nor direct-initialization. #1911

Closed
RealLitb opened this issue Feb 11, 2018 · 6 comments
Assignees

Comments

@RealLitb
Copy link

Over.match.ctor says

"When objects of class type are direct-initialized, copy-initialized from an expression of the same or a derived class type ([dcl.init]), or default-initialized, overload resolution selects the constructor. For direct-initialization or default-initialization that is not in the context of copy-initialization, the candidate functions are all the constructors of the class of the object being initialized. For copy-initialization, the candidate functions are all the converting constructors of that class. "

The last sentence should consider the remaining default initialization cases aswell that happened in the context of copy(-list)-initializatizion. Suggested edit:

"For copy-initialization and the remaining default-initialization cases, the candidate functions are all the converting constructors of that class."

Note that initialization by "()" is not copy-initializaton (neither is it direct initialization), so this change is normatively relevant. However, I think the current intent is sufficiently clear so this could be handled editorially.

@cpplearner
Copy link
Contributor

initialization by "()"

(When) is it not covered by [dcl.init]/16?

The initialization that occurs in the forms

T x(a);
T x{a};

as well as in new expressions, static_­cast expressions, functional notation type conversions, mem-initializers, and the braced-init-list form of a condition is called direct-initialization.

@RealLitb
Copy link
Author

Because "(a)" is different from "()". That's how I read it, even though I wish it was clearer.

But, if it was covered by that, then "For direct-initialization or default-initialization that is not in the context of copy-initialization ..." could be simplified to "For direct-initialization ..." straight away. And we could always use explicit constructors in the context of copy-list-initializations. Which seems... odd and against the intentions.

@cpplearner
Copy link
Contributor

cpplearner commented Feb 11, 2018

I mean, can the initializer "()" appear outside of new expressions, functional notation type conversions, or mem-initializers (i.e. the contexts listed after "as well as in")?

(I think T x(a); does not cover T x(); bacause it is not even a variable declaration.)

@RealLitb
Copy link
Author

RealLitb commented Feb 11, 2018

T x() can happen if a variadic template instantiates it from T x(args...);. It also appears in this context:

struct T { explicit T() { } };
T t = {};

Here, we are told by list-initialization clauses, to value-initialize t. And that means to default-initialize t. And that means to consider over.match.ctor with an initializer (). This initializer doesn't appear in code, but merely needed for the conditional verbiage in over.match.ctor.

Ok, now that you mention new-expressions, functional notation type conversions etc, I can see why it's deeply confusing. Yes, I agree, I think in some cases () is considered direct initialization, and in other cases, like my above examples, it is not.

@timsong-cpp
Copy link
Contributor

And we use \grammarterm for "the initializer ()" in the description of default-initialization, but () doesn't match the initializer production at all.

@jensmaurer jensmaurer changed the title Initialization by "()" neither is copy-initialization nor direct-initialization. [over.match.ctor] Initialization by "()" neither is copy-initialization nor direct-initialization. Feb 14, 2018
@jensmaurer jensmaurer added the decision-required A decision of the editorial group (or the Project Editor) is required. label Feb 14, 2018
@jensmaurer
Copy link
Member

Editorial meeting consensus: First issue, fixed by "For copy-initialization (including default initialization in the context of copy-initialization), the candidate functions are all the converting constructors of that class."
11.6p16 morph to bulleted list; fix "of the form" declaration-lookalikes to instead inspect grammar non-terminals.

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

4 participants