From: Douglas Gregor Date: Sun, 12 Sep 2010 03:38:25 +0000 (+0000) Subject: Don't perform integral promotions from an incompletion enumeration X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5dde1605da5e6db8a9214f4a5d094ae0bbc64a4e;p=clang Don't perform integral promotions from an incompletion enumeration 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 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 89356c24b2..7ec5f3ac81 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -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()) - if (ToType->isIntegerType()) + if (ToType->isIntegerType() && + !RequireCompleteType(From->getLocStart(), FromType, PDiag())) return Context.hasSameUnqualifiedType(ToType, FromEnumType->getDecl()->getPromotionType()); diff --git a/test/SemaCXX/enum.cpp b/test/SemaCXX/enum.cpp index 1dc55e3916..b4a050cb09 100644 --- a/test/SemaCXX/enum.cpp +++ b/test/SemaCXX/enum.cpp @@ -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'}} +}