]> granicus.if.org Git - clang/commitdiff
The underlying type for an enum should be an integer type, not another enum.
authorEli Friedman <eli.friedman@gmail.com>
Tue, 18 Dec 2012 02:37:32 +0000 (02:37 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 18 Dec 2012 02:37:32 +0000 (02:37 +0000)
(This change only affects ObjC.)

<rdar://problem/12857117>.

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

lib/Sema/SemaDecl.cpp
test/SemaObjC/enum-fixed-type.m

index ab931a773fdd4f256d1686ab51233003a27d058b..4bccc1c987041f600a68d0df9498cd98145ba1a7 100644 (file)
@@ -8454,9 +8454,13 @@ bool Sema::CheckEnumUnderlyingType(TypeSourceInfo *TI) {
   SourceLocation UnderlyingLoc = TI->getTypeLoc().getBeginLoc();
   QualType T = TI->getType();
 
-  if (T->isDependentType() || T->isIntegralType(Context))
+  if (T->isDependentType())
     return false;
 
+  if (const BuiltinType *BT = T->getAs<BuiltinType>())
+    if (BT->isInteger())
+      return false;
+
   Diag(UnderlyingLoc, diag::err_enum_invalid_underlying) << T;
   return true;
 }
index 4fe643faef2f7647d34b8a4a5e10dddd5bde6d2d..6fd400a637e4b433d9aa2c8150f913ac0c5c9aa9 100644 (file)
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 #if !__has_feature(objc_fixed_enum)
 #  error Enumerations with a fixed underlying type are not supported
@@ -36,3 +35,6 @@ int arr2[(sizeof(typeof(IntegerEnum)) == sizeof(typeof(long))) - 1];
 // <rdar://problem/10760113>
 typedef enum : long long { Bar = -1 } LongLongEnum;
 int arr3[(long long)Bar == (long long)-1 ? 1 : -1];
+
+typedef enum : Integer { BaseElem } BaseEnum;
+typedef enum : BaseEnum { DerivedElem } DerivedEnum; // expected-error {{non-integral type 'BaseEnum' is an invalid underlying type}}