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
Clarify that direct-initialized, copy-initialized from E #4582
Comments
Why?
If we say it's direct-initialized, we mean it's initialized using direct-initialization. Similarly for copy-initialized. I don't understand why there would be any doubt about that. Direct-initialized means |
Such as struct A{
A(int); //#1
};
A a = static_cast<A>(0); According to expr.static.cast#4, that says the result object |
I think we say "X-list-initialized" everywhere we mean it. Anywhere we initialize from a single expression, it's understood to be non-list-initialization. In some case, it depends on the form of the initializer (possibly given elsewhere) what we do. |
Actually, the issue is caused by https://stackoverflow.com/questions/67016640/why-cant-a-prvalue-of-array-type-be-converted-to-the-same-type-using-static-cas. int main(){
using T = int[2];
T arr = T{1,2};
} Major implements complain that the above code is ill-formed. However, as per [expr.type.conv#2]
Here the wording is "direct-initialized", which is equivalent to that the direct-initialization of the result object from the initializer where the initializer is Moreover, the whole [dcl.init.general] is most using either So, my point is, could we say that "Y is X-initialized from E" will model a declaration T Y = E; For direct-initialized from E, it T Y E; otherwise, if T Y(E); Now, |
To your first point, the "direct-initialized" in [expr.type.conv] is correct, because it applies to both parenthesized expression-lists and to braced-init-lists. From there, we go to do [dcl.init] p15, and p15.1 branches off to [dcl.init.list] right away. [dcl.init.list] p3.4, in turn, goes to [dcl.init.aggr] and everything should work fine. To your second point, I think the wording is sufficiently clear in intent that "direct-initialized from expression E" means "direct-non-list-initialized with source E" in the parlance of [dcl.init] p15. I do sympathize with clearly saying "direct-non-list-initialized" (or copy-non-list-initialized") for these cases. |
So, for the first point, we all agree that GCC and Clang have the wrong interpretation for the case. For the second point, the whole [dcl.init]p15 is based on a destination type and a source type to state the relevant initialization where the source type is derived from the initializer expression
However, some initializations are not triggered by a declaration with an initializer. Such as, it says that "Y is X-initialized from E". Could we say that |
We agree that E is not an initializer per the grammar; but I think it's reasonable to consider it an "initializer expression". Would you be happier if we said "... direct-initialized from the initializer expression E..." everywhere we used "from E" nowadays? |
No, I wouldn't. That would be a bit duplicate. Since there's no normative definition for |
So, back to saying "direct-non-list-initialized" and "copy-non-list-initialized" where we talk about expressions (as opposed to braced-init-lists). |
I think we are not necessary to say "direct-non-list-initialized" and "copy-non-list-initialized", since the following rule
That means, Only the Similarly, in the aggregate initialization, in some section, it says
That means the corresponding initialization is specified by [dcl.init#general]#15.1, however, the paragraph says
It refers to the |
Editorial meeting 2021-04-16: We have an in-between situation here. [dcl.init] should either state the complete set of places where which initialization happens (and then we just say X is initialized by "grammar"), or any place should be specific and say "direct-non-list-initialization" and the lists of places in [dcl.init] should be removed. Consensus: Remove all "where" info from dcl.init and make sure all users of dcl.init are clear what kind of initialization they want. Have CWG review the change. |
@jensmaurer The addition to this issue.
Since [dcl.init.general] p16.3 says
How about this? T t = E; In this declaration, the initializer is
Consider [over.match.ctor] p1
In this rule, the initializer refers to the grammatical initializer. For this rule, consider this example struct T{
T(int);
};
T x = static_cast<T>(0); According to [expr.static.cast] p4
The intent is [dcl.init.general] p16.6.2 and [over.match.ctor] apply here. However, what is the initializer of this direct-initialization in the context where the result object is direct-initialized from
when [over.match.ctor] is checked for this direct-initialization, what is the initializer in this context? It is also not clearly specified. |
Presumably, "direct-initialized from E" and "copy-initialized from E" should be distinguishable with direct-initialization and copy-initialization. The initialization might be considered as an expression, as per
I mean that an
initialization
has been a recipe(comprises the function will be called, if any) whose evaluation will initialize the destination object. However,direct(copy)-initialized from E
might be a bit different.There are many such a usage in the standard, such as
expr.static.cast#4
dcl.dcl#dcl.init.aggr-5
So, what's the appearance of form here for copy-initialize or direct-initialize respectively? In other words, if we say that an entity
t
is direct-initialized from an expressionE
, what's the form?Does it refer to
#1
or#2
? Similarly, when we say that an entityt
is copy-initialized from an expressionE
, what's the form?It does not specify in the standard.
The text was updated successfully, but these errors were encountered: