-
Notifications
You must be signed in to change notification settings - Fork 7
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
CWG2894 [expr.type.conv] T{...}
Functional casts create prvalues of reference type T
#536
Comments
I'll revisit this and come up with some wording later. Related to GCC Bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115085. Originally discovered at https://stackoverflow.com/q/78475217/5740428. Supersedes https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1521 |
May be related: is it clear in [expr.type.conv] that |
I think it's semi-clear, but far from obvious. None of the other sentences really apply here, so the result is a prvalue of type Maybe I've missed some other wording that handles it more directly. |
OK, here's a shot at a resolution. I copied some wording from [conv.general].
|
@t3nsor looks good to me normatively, but it's sufficiently complicated so that I'd split it into bullets. Update: your wording seems to be missing a definition of |
I've updated the proposed wording to include a definition of |
Actually now looking at this, the wording is even more defective because Specifically, it would be wrong to say "the initializer shall have at most one element" instead of insisting on value-initialization because this makes @t3nsor thanks for the good starting point; the post has its own proposed wording now. |
Also on another note, we should probably add wording to [dcl.init] that bans |
I think they've been banned by CWG2475 in [dcl.pre]. |
Ah I didn't realize that |
T{...}
Functional casts create prvalues of reference type T
T{...}
Functional casts create prvalues of reference type T
Note to self: The current proposed resolution implies the creation of a separate temporary object in the case of non-reference The first half of the resolution is OK (up to We can borrow wording from https://eel.is/c++draft/expr.static.cast#4 which has a mixed approach of invented variable for reference types, and forwarding the expression to direct-initialization otherwise. |
I think bifurcating the wording that describes how the initialization is done for reference and non-reference types in all cases (including changing the existing [conv.general]/6) would be unfortunate. It obfuscates what we're really trying to say, which is "initialize the result of this expression the same way you would initialize this invented variable". I think we should just try to find a way of saying that that makes it clear that there's not really an intermediate variable. |
Very rough idea:
Then repeat the same wording in [conv.general] and [expr.static.cast]. We could even factor out the part that tells you the value category, but I can't come up with a decent way of saying it. |
"result is determined by the rules" sounds a bit too non-specific for my taste. We say what rules are involved in determining the result, but we don't say what the result is. Too much reading between the lines. I really can't think of a good way around splitting the wording for references and object types. However, we can unify the wording between here and
We can specify the type adjustment rules in [expr.type] p1 more concretely and then talk about a "result object or reference" in [expr.type.conv]. This should work and would be quite concise, but I personally dislike crutching on [expr.type]. |
I've updated CWG2894 with the minimum fix. Any larger consolidations / rearrangements need specific wording suggestions. |
Reference: [expr.type.conv] paragraph 2, sentence 3
Issue description
In
T{...}
, ifT
is a reference type, [expr.type.conv] paragraph 2, sentence 3 applies, stating:This is defective for references; there can be no prvalues of reference type.
Furthermore, it is not sufficiently clear that
void(1, 2)
andvoid{1}
are not valid. All compilers reject these forms, and should.Suggested resolution
Update [expr.type.conv] paragraph 2 as follows:
To [expr.type.conv] paragraph 2, append an example:
[Editor's note: The example is intended to be educational and highlight the cases
void(1, 2)
,R{a}
, which currently have wording issues or related compiler bugs.]The text was updated successfully, but these errors were encountered: