[Clang] Incorrect overflow check and evaluation for MS integer literal suffixes (i8/i16/i32/i64)
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Inspired by #212504
I discovered other issues while trying to fix this assertion.
For code : `static_assert(-255i8, "");` Surprisingly, the current mainline Clang doesn't produce any errors or warnings at all.
The current Clang mainline produces neither errors nor warnings for this, yet the value is actually truncated; consequently, it fails the assertion `static_assert(-255i8 == -255, "-255 != -255 ?")`.
https://godbolt.org/z/K88b1sxz9
This drew my attention to the fact that the logic handling Microsoft-style integer literal extensions appears quite fragile. I plan to submit a patch later, though some edge cases may still require further discussion.
For example, how should `-128i8` be handled?
Contributor guide
Research direction
Reproduce the two static_assert examples and inspect Clang's handling of Microsoft-style i8/i16/i32/i64 integer literal suffixes. Clarify the intended behavior for boundary cases such as -128i8, then ensure overflow, truncation, diagnostics, and constant evaluation are consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100