-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Replace = with {} initialization, even for auto declared variables
#2296
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
base: master
Are you sure you want to change the base?
Replace = with {} initialization, even for auto declared variables
#2296
Conversation
Adjusted all code example according to "ES.23: Prefer the {}-initializer syntax".
Note that this rule does _allow_ using `=` with `auto`, but it appears more consistent to just use the `{}` syntax for `auto` as well.
1f4b81a to
b21864c
Compare
|
Personally I would prefer to rewrite (or remove) ES.23
Those are all debatable.
Probably true.
Or when you are writing generic templates and don't want to gratuitously reject code that actually works fine. Almost every time we've used |
|
Thank you for your reply, @jwakely ! Note that this pull request still allows users to use On the other hand, I would be very interested to see an update of ES.23 that would possibly make things clearer. |
|
Editors call: We haven't reviewed this because it's marked draft -- if it's ready for us to review it please mark it non-draft. Thanks! |
|
If I understand correctly, the Guidelines allow using |
| int area(int height, int width) | ||
| { | ||
| auto res = height * width; | ||
| auto res {height * width}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using the proposed {} for auto, some very old C++11 compilers might deduce res as an initializer_list<int>, instead of an int. For example, GCC 4.9.4: https://godbolt.org/z/G8G9v7qss Would that be a reason for rejecting this pull request?
In general, should the examples still have auto var = expr, instead of auto var {expr}, in order to support those old C++11 compilers?
Adjusted all code example according to ES.23: Prefer the
{}-initializer syntax.Note that this rule does allow using
=withauto, but it appears more consistent to just use the{}syntax forautoas well.Honestly it's also OK for me to use
=withauto, but then I would still like to know if the code examples are really meant to support using=withauto. Otherwise I think it's clearer to just use the{}syntax in the code examples (as proposed by this pull request).