Skip to content

[ub:expr.shift.neg.and.width] Use std::uint32_t instead of int in example#9187

Closed
eisenwave wants to merge 1 commit into
cplusplus:mainfrom
eisenwave:ub-shift
Closed

[ub:expr.shift.neg.and.width] Use std::uint32_t instead of int in example#9187
eisenwave wants to merge 1 commit into
cplusplus:mainfrom
eisenwave:ub-shift

Conversation

@eisenwave

@eisenwave eisenwave commented Jul 16, 2026

Copy link
Copy Markdown
Member

Firstly, I find it unnatural to use int and then have to assert various properties to get 32-bit type.

Secondly, the example is incorrect (well, not really, it's still true that a 32-bit shift is UB) because sizeof(int) == 4 && CHAR_BIT == 8 is not a sufficient assertion. It's possible that int is a 16-bit type, with two 8-bit padding bytes and two 8-bit value bytes.

Alternatively, we could also use numeric_limits<int>::digits in the assertion or just put the assumption about the width of int into prose.

@eisenwave eisenwave added P3-Other Triaged issue not in P1 or P2 ub-ifndr UB and IFNDR Annex labels Jul 16, 2026
@eisenwave eisenwave requested a review from notadragon July 16, 2026 12:38

@notadragon notadragon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have the #include <cstdint>. I would also prefer that we roll this into https://isocpp.org/files/papers/D4284R0.pdf for discoverability, but otherwise this is fine.

@eisenwave eisenwave closed this Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3-Other Triaged issue not in P1 or P2 ub-ifndr UB and IFNDR Annex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants