]> granicus.if.org Git - clang/commitdiff
Don't perform integral promotions from an incompletion enumeration
authorDouglas Gregor <dgregor@apple.com>
Sun, 12 Sep 2010 03:38:25 +0000 (03:38 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sun, 12 Sep 2010 03:38:25 +0000 (03:38 +0000)
type. Fixes PR8089 in a slightly different way than had been suggested.

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

lib/Sema/SemaOverload.cpp
test/SemaCXX/enum.cpp

index 89356c24b2c3868c91cf03724c472eb55a3da079..7ec5f3ac81369f3bae3457a4a2c0edb8d99c0ca9 100644 (file)
@@ -1194,7 +1194,8 @@ bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) {
 
   // We pre-calculate the promotion type for enum types.
   if (const EnumType *FromEnumType = FromType->getAs<EnumType>())
-    if (ToType->isIntegerType())
+    if (ToType->isIntegerType() && 
+        !RequireCompleteType(From->getLocStart(), FromType, PDiag()))
       return Context.hasSameUnqualifiedType(ToType,
                                 FromEnumType->getDecl()->getPromotionType());
 
index 1dc55e39162bdbdcc8ed1449d7d5bdcc1c16c48d..b4a050cb0908e7b4519c01938f5deade0a8bd289 100644 (file)
@@ -90,3 +90,8 @@ typedef enum { }; // expected-warning{{typedef requires a name}}
 enum PR7921E {
     PR7921V = (PR7921E)(123) // expected-error {{expression is not an integer constant expression}}
 };
+
+void PR8089() {
+  enum E; // expected-error{{ISO C++ forbids forward references to 'enum' types}}
+  int a = (E)3; // expected-error{{cannot initialize a variable of type 'int' with an rvalue of type 'E'}}
+}