Fix a few enum-related fixme's
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41513 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index ba2fc80..be61d73 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -936,6 +936,9 @@
llvm::APSInt EnumVal(32);
QualType EltTy;
if (Val) {
+ // Make sure to promote the operand type to int.
+ UsualUnaryConversions(Val);
+
// C99 6.7.2.2p2: Make sure we have an integer constant expression.
SourceLocation ExpLoc;
if (!Val->isIntegerConstantExpr(EnumVal, Context, &ExpLoc)) {
@@ -952,17 +955,19 @@
// Assign the last value + 1.
EnumVal = LastEnumConst->getInitVal();
++EnumVal;
- // FIXME: detect overflow!
+
+ // Check for overflow on increment.
+ if (EnumVal < LastEnumConst->getInitVal())
+ Diag(IdLoc, diag::warn_enum_value_overflow);
+
EltTy = LastEnumConst->getType();
} else {
// First value, set to zero.
EltTy = Context.IntTy;
- // FIXME: Resize EnumVal to the size of int.
+ EnumVal.zextOrTrunc(Context.getTypeSize(EltTy, IdLoc));
}
}
- // TODO: Default promotions to int/uint.
-
// TODO: If the result value doesn't fit in an int, it must be a long or long
// long value. ISO C does not support this, but GCC does as an extension,
// emit a warning.