We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The left shift of a signed integer is officially undefined behavior in C++17 and earlier: https://en.cppreference.com/w/cpp/language/operator_arithmetic#Bitwise_shift_operators
In C++20, signed integers are officially two's-complement, so left-shift becomes well defined: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0907r4.html.
Consider to fix it by generating the following code instead of a << b:
a << b
a * (1 << b);
The text was updated successfully, but these errors were encountered:
See also Java spec: https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.19 And Python reference: https://docs.python.org/3/reference/expressions.html#shifting
Sorry, something went wrong.
Note that it seems that modern compilers can optimize multiplication with power of two - see in godbolt.
[#671] Implement left shift operator by multiplication in C++
d9de529
* extend language tests
9ed1b81
Mi-La
No branches or pull requests
The left shift of a signed integer is officially undefined behavior in C++17 and earlier: https://en.cppreference.com/w/cpp/language/operator_arithmetic#Bitwise_shift_operators
In C++20, signed integers are officially two's-complement, so left-shift becomes well defined: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0907r4.html.
Consider to fix it by generating the following code instead of
a << b
:The text was updated successfully, but these errors were encountered: