aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2012-12-18 02:37:32 +0000
committerEli Friedman <eli.friedman@gmail.com>2012-12-18 02:37:32 +0000
commit2fcff83aa4f62b96b98cde967c8fbacc74f3ab9f (patch)
tree3a364001634404fbf72a0feb02b859c9b7e55ac7
parentb52cc89e1bd43457f1f370670f85e518ae5329b0 (diff)
The underlying type for an enum should be an integer type, not another enum.
(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
-rw-r--r--lib/Sema/SemaDecl.cpp6
-rw-r--r--test/SemaObjC/enum-fixed-type.m4
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index ab931a773f..4bccc1c987 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -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;
}
diff --git a/test/SemaObjC/enum-fixed-type.m b/test/SemaObjC/enum-fixed-type.m
index 4fe643faef..6fd400a637 100644
--- a/test/SemaObjC/enum-fixed-type.m
+++ b/test/SemaObjC/enum-fixed-type.m
@@ -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}}