[cfe-commits] r170402 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaObjC/enum-fixed-type.m
Eli Friedman
eli.friedman at gmail.com
Mon Dec 17 18:37:33 PST 2012
Author: efriedma
Date: Mon Dec 17 20:37:32 2012
New Revision: 170402
URL: http://llvm.org/viewvc/llvm-project?rev=170402&view=rev
Log:
The underlying type for an enum should be an integer type, not another enum.
(This change only affects ObjC.)
<rdar://problem/12857117>.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaObjC/enum-fixed-type.m
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=170402&r1=170401&r2=170402&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Dec 17 20:37:32 2012
@@ -8454,9 +8454,13 @@
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;
}
Modified: cfe/trunk/test/SemaObjC/enum-fixed-type.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/enum-fixed-type.m?rev=170402&r1=170401&r2=170402&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/enum-fixed-type.m (original)
+++ cfe/trunk/test/SemaObjC/enum-fixed-type.m Mon Dec 17 20:37:32 2012
@@ -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 @@
// <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}}
More information about the cfe-commits
mailing list