From: Richard Smith Date: Sat, 28 Mar 2015 00:31:40 +0000 (+0000) Subject: A conversion from a scoped enumeration bitfield to an integral type is an X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=228d42a03389cbe43bfce03d7544cbf30b855a23;p=clang A conversion from a scoped enumeration bitfield to an integral type is an 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 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index fbf110b321..cf84f23baf 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -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. diff --git a/test/SemaCXX/enum-bitfield.cpp b/test/SemaCXX/enum-bitfield.cpp index ec849b79a7..676ae44b37 100644 --- a/test/SemaCXX/enum-bitfield.cpp +++ b/test/SemaCXX/enum-bitfield.cpp @@ -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);