]> granicus.if.org Git - clang/commitdiff
When diagnosing enumerator values outside of the range of 'int', be
authorDouglas Gregor <dgregor@apple.com>
Wed, 17 Feb 2010 22:40:11 +0000 (22:40 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 17 Feb 2010 22:40:11 +0000 (22:40 +0000)
sure that we get the "too large" vs. "too small" part of the
diagnostic correct.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96524 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/enum.c

index 38211134393058d2fc6d2496b6d34513062289a8..e7217dc2200dce59ffcdd41e0251da0bf0cb67a8 100644 (file)
@@ -5732,7 +5732,7 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
           if (!isRepresentableIntegerValue(Context, EnumVal, Context.IntTy))
             Diag(IdLoc, diag::ext_enum_value_not_int)
               << EnumVal.toString(10) << Val->getSourceRange()
-              << EnumVal.isNonNegative();
+              << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
           else if (!Context.hasSameType(Val->getType(), Context.IntTy)) {
             // Force the type of the expression to 'int'.
             ImpCastExprToType(Val, Context.IntTy, CastExpr::CK_IntegralCast);
index 9b4650091e19624cf3d8571c5aff2b47ac59cf32..6177edff91c4de61f571bf15aec5d6fa3a1b1e5a 100644 (file)
@@ -9,7 +9,8 @@ enum g {  // too negative
    c = -2147483649,         // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
    d = 2147483647 };
 enum h { e = -2147483648, // too pos
-   f = 2147483648           // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+   f = 2147483648,           // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
+  i = 0xFFFF0000 // expected-warning {{too large}}
 }; 
 
 // minll maxull