-
Notifications
You must be signed in to change notification settings - Fork 251
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
[SUGGESTION] Definite first assignment to return this
#368
Comments
This does mean that,
|
Thanks. I agree with being consistent. But (contrarian here) I was actually thinking of going the other way: Option 1: Have assignment return and/or Option 2: Leave assignment alone for Cpp1 compatibility, but disallow writing chained assignments in Cpp2 code. I think Option 2 is a good thing to do regardless, so I'll do that now... Re this:
I don't understand? Assignment does not have to be discarded, I agree that whatever is done here, we should not require discarding the result of an |
You're right. |
I remember isocpp/CppCoreGuidelines#1988. |
Yes, my commit just now "fixes" that for |
That was it, thanks! Browsing that, the additional use case mentioned there was using the result as an lvalue, such as So I think the remaining question for this issue, after the above commit to make assignment and discarding more regular, is whether we want to keep the issue open to allow definite first uses like this:
I see arguments for both that the above should be supported and that the above should be banned...? |
Adding to the previous comment: The specific use case of So I think I've come down to that a definite first use initialization should be a whole statement, not a subexpression. TODO: I should create a diagnostic for that so that a violation gets a nice readable error message |
That's certainly consistent with definite first use initialization of data members in |
At #366 (comment),
we discovered that a definite first assignment has type
void
.Returning an lvalue reference to the object parameter
is only a convention in user-provided
operator=
(C++𝘕).That's the language's default,
and what is expected of a regular type.
There should be worth in Cpp2 unifying not only syntax,
but also the semantics of its
operator=
.This should eliminate future guidance
around a first assignment behaving differently on whether it's definite.
It should be worth noting that
the C++1 methods to delay object creation
return a reference or pointer to the created object.
The C++ standard library follows suit,
and I can't come up with a reason for Cpp2 not to.
The text was updated successfully, but these errors were encountered: