-
Notifications
You must be signed in to change notification settings - Fork 246
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
[BUG] z: u8 = x + y; does not compile #1318
Comments
That's integral promotion. |
Yes indeed, but is it a bug? |
See Type/value queries and casts. |
Even if it is integral promotion, the C++1 version works without any problems. https://godbolt.org/z/PEfeaPvn1
So even if it is not a bug, it is a strong inconvenience. Maybe cpp2::move needs to be extended to prevent this. |
It's because the lowered Cpp1 uses list-initialization, which prevents narrowing. |
Ok, I had a closer look. List-initialization for
Error:
So it is the integral promotion you suggested. This seems to be one of those corner cases where the language behaves quite weird. If this would be a generalized rule then also
should give the same warning. |
This makes me wonder if "move from last use" should ignore fundamental types, just to avoid the unnecessary complexity in the generated code. |
I also think |
How would you constrain it in that case though? |
|
@DyXel It doesn't really do things differently any more. @hsutter couldn't remember why it did things differently, so maybe the need was removed in another way, or maybe it's just been broken again. It's now just this:
|
See the linked commit's comments: de3f54f#comments. |
Huh, that's interesting. I thought the original problem was that some objects that were supposed to not be moved were being moved. Like the original example in #1002 . Its quite inconvenient if the common pattern of locking a mutex would require you to discard the mutex later. |
@JohelEGP Thanks, I didn't scroll to the bottom. :) |
The following code does not compile.
main.cpp2
main.cpp1 generated
Compiler error
Example
https://cpp2.godbolt.org/z/r6r9d8KMP
The text was updated successfully, but these errors were encountered: