This fixes https://github.com/llvm/llvm-project/issues/52873.
Don't warn in C++2A mode (and newer), as signed left shifts
always wrap and never overflow. Ref. -
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1236r1.html.
Details
- Reviewers
aaron.ballman - Group Reviewers
Restricted Project
Diff Detail
Event Timeline
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
11418 | ... to early here instead, and it should also check isSignedOverflowDefined() (note: we should probably fix SignedOverflowBehavior in LangOptions.def to be set based on the C++ language mode instead of needing to check for C++20 specifically) | |
11418–11428 | and then we can remove the check for signed overflow defined or C++20 here because we've already bailed out. | |
11458–11459 | I think this should move up... |
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
11418–11428 | I think we'd want to remove the CPlusPlus20 check here, right? Signed-overflow should cover this case as well, and the check for C++20 below is no longer necessary? |
clang/lib/Sema/SemaExpr.cpp | ||
---|---|---|
11419–11421 | I think this should also be checking || isSignedOverflowDefined() -- if signed overflow is defined, then all the rest of the diagnostics shouldn't be triggered because the behavior is defined. (Eventually, we should remove the check for CPlusPlus20 and use ONLY isSignedOverflowDefined() -- that should account for the current language mode instead of requiring us to check additional predicates. But that doesn't have to be fixed up as part of this patch.) | |
11419–11428 | Then the isSignedOverflowDefined() check can be removed here. |
Done, Thank you for reviewing.
Committed in https://reviews.llvm.org/rG48e1829874df15fd57e731d4824604f28e177585.
... to early here instead, and it should also check isSignedOverflowDefined() (note: we should probably fix SignedOverflowBehavior in LangOptions.def to be set based on the C++ language mode instead of needing to check for C++20 specifically)