]> granicus.if.org Git - clang/commitdiff
A conversion from a scoped enumeration bitfield to an integral type is an
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 28 Mar 2015 00:31:40 +0000 (00:31 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 28 Mar 2015 00:31:40 +0000 (00:31 +0000)
integral promotion only if it converts to the underlying type or its promoted
type, not if it converts to the promoted type that the bitfield would have it
if were of the underlying type.

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

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

index fbf110b321e469932a6880ed6e8063c935977331..cf84f23baf43060713af714ac20ea6708068a123 100644 (file)
@@ -1752,11 +1752,13 @@ bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) {
       return false;
 
     // We can perform an integral promotion to the underlying type of the enum,
-    // even if that's not the promoted type.
+    // even if that's not the promoted type. Note that the check for promoting
+    // the underlying type is based on the type alone, and does not consider
+    // the bitfield-ness of the actual source expression.
     if (FromEnumType->getDecl()->isFixed()) {
       QualType Underlying = FromEnumType->getDecl()->getIntegerType();
       return Context.hasSameUnqualifiedType(Underlying, ToType) ||
-             IsIntegralPromotion(From, Underlying, ToType);
+             IsIntegralPromotion(nullptr, Underlying, ToType);
     }
 
     // We have already pre-calculated the promotion type, so this is trivial.
index ec849b79a74608b2b6e9f8fbc416ac36ab565b36..676ae44b37fe5a542f202304cd637b6e4f965fd7 100644 (file)
@@ -28,3 +28,11 @@ struct D {
   A::B : C;
 };
 }
+
+enum WithUnderlying : unsigned { wu_value };
+struct WithUnderlyingBitfield {
+  WithUnderlying wu : 3;
+} wu = { wu_value };
+int want_unsigned(unsigned);
+int want_unsigned(int) = delete;
+int check_enum_bitfield_promotes_correctly = want_unsigned(wu.wu);