diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2012-12-18 02:37:32 +0000 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2012-12-18 02:37:32 +0000 |
| commit | 52f32b9b2be52b50377ec6a7315bbf079692aeaf (patch) | |
| tree | d1feb1254f6f960afb0e109d7bb3167f667d1063 | |
| parent | 62737b65b17349d08159c3126c16497d34a97ac1 (diff) | |
| download | bcm5719-llvm-52f32b9b2be52b50377ec6a7315bbf079692aeaf.tar.gz bcm5719-llvm-52f32b9b2be52b50377ec6a7315bbf079692aeaf.zip | |
The underlying type for an enum should be an integer type, not another enum.
(This change only affects ObjC.)
<rdar://problem/12857117>.
llvm-svn: 170402
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 6 | ||||
| -rw-r--r-- | clang/test/SemaObjC/enum-fixed-type.m | 4 |
2 files changed, 8 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index ab931a773fd..4bccc1c9870 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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/clang/test/SemaObjC/enum-fixed-type.m b/clang/test/SemaObjC/enum-fixed-type.m index 4fe643faef2..6fd400a637e 100644 --- a/clang/test/SemaObjC/enum-fixed-type.m +++ b/clang/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}} |

