// 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.
+ unsigned IntWidth = Context.getTypeSize(Context.IntTy, Enum->getLocation());
// Verify that all the values are okay, and reverse the list.
EnumConstantDecl *ECD =
cast_or_null<EnumConstantDecl>(static_cast<Decl*>(Elements[i]));
if (!ECD) continue; // Already issued a diagnostic.
+
+ // If the enum value doesn't fit in an int, emit an extension warning.
+ assert(ECD->getInitVal().getBitWidth() >= IntWidth &&
+ "Should have promoted value to int");
+ const llvm::APSInt &InitVal = ECD->getInitVal();
+ if (InitVal.getBitWidth() > IntWidth) {
+ llvm::APSInt V(InitVal);
+ V.trunc(IntWidth);
+ V.extend(InitVal.getBitWidth());
+ if (V != InitVal)
+ Diag(ECD->getLocation(), diag::ext_enum_value_not_int,
+ InitVal.toString());
+ }
ECD->setNextDeclarator(EltList);
EltList = ECD;
"duplicate member '%0'")
DIAG(err_enum_value_not_integer_constant_expr, ERROR,
"enumerator value for '%0' is not an integer constant")
+DIAG(ext_enum_value_not_int, EXTENSION,
+ "ISO C restricts enumerator values to range of 'int' (%0 is too large)")
DIAG(err_case_label_not_integer_constant_expr, ERROR,
"case label does not reduce to an integer constant")
DIAG(err_typecheck_illegal_vla, ERROR,