[clang] [ExprConstant] Handle shift overflow the same way as other kinds of overflow (PR #99579)
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 18 16:21:49 PDT 2024
================
@@ -200,14 +200,7 @@ namespace LongInt {
};
enum shiftof {
- X = (1<<-29), // all-error {{expression is not an integral constant expression}} \
- // all-note {{negative shift count -29}}
-
- X2 = (-1<<29), // cxx17-error {{expression is not an integral constant expression}} \
- // cxx17-note {{left shift of negative value -1}} \
- // ref-cxx17-error {{expression is not an integral constant expression}} \
- // ref-cxx17-note {{left shift of negative value -1}}
-
- X3 = (1<<32) // all-error {{expression is not an integral constant expression}} \
- // all-note {{shift count 32 >= width of type 'int'}}
+ X = (1<<-29),
+ X2 = (-1<<29),
+ X3 = (1<<32),
----------------
zygoloid wrote:
It's concerning that we don't produce a warning by default for constant-folding this, especially given that GCC does not constant-fold bad shifts. I'm not sure it's OK that we start silently accepting this invalid code by default. I wonder if we could reasonably refuse to constant-fold if the evaluation had UB?
https://github.com/llvm/llvm-project/pull/99579
More information about the cfe-commits
mailing list