Skip to content
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

Consider to implement left shift operator by multiplication in C++ #50

Closed
mikir opened this issue Dec 4, 2024 · 0 comments
Closed

Consider to implement left shift operator by multiplication in C++ #50

mikir opened this issue Dec 4, 2024 · 0 comments
Assignees
Milestone

Comments

@mikir
Copy link
Collaborator

mikir commented Dec 4, 2024

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 * (1 << b);

This is issue is connected to the Zserio issue #671.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant