[clang] [clang][Sema] Fix for enums overflowing (#24667) (PR #78742)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 27 12:12:22 PST 2024
================
@@ -19807,20 +19807,46 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
// sufficient to contain the incremented value. If no such type
// exists, the program is ill-formed.
QualType T = getNextLargerIntegralType(Context, EltTy);
- if (T.isNull() || Enum->isFixed()) {
+ if (Enum->isFixed()) {
// There is no integral type larger enough to represent this
// value. Complain, then allow the value to wrap around.
EnumVal = LastEnumConst->getInitVal();
EnumVal = EnumVal.zext(EnumVal.getBitWidth() * 2);
++EnumVal;
- if (Enum->isFixed())
- // When the underlying type is fixed, this is ill-formed.
- Diag(IdLoc, diag::err_enumerator_wrapped)
- << toString(EnumVal, 10)
- << EltTy;
- else
+ // When the underlying type is fixed, this is ill-formed.
+ Diag(IdLoc, diag::err_enumerator_wrapped)
+ << toString(EnumVal, 10) << EltTy;
+
+ } else if (T.isNull()) {
+ if (EltTy->isSignedIntegerType() &&
+ (getLangOpts().CPlusPlus ||
+ LangStandard::getLangStandardForKind(getLangOpts().LangStd)
+ .isC23())) {
----------------
wheatman wrote:
Thanks you, I did see that in my looking
https://github.com/llvm/llvm-project/pull/78742
More information about the cfe-commits
mailing list