diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-06-28 21:17:55 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-06-28 21:17:55 +0000 |
commit | aadb254a79558de8ad5911ac7b4a6dacb45d44dc (patch) | |
tree | 5893a0f17b5372e26ddbbe6d1f4c9bb87d777e49 /clang/lib/Sema/SemaOverload.cpp | |
parent | 019d3cd3b4c08dd2d39def08c983f3af9f9b2cd9 (diff) | |
download | bcm5719-llvm-aadb254a79558de8ad5911ac7b4a6dacb45d44dc.tar.gz bcm5719-llvm-aadb254a79558de8ad5911ac7b4a6dacb45d44dc.zip |
PR37979: integral promotions in C++ treat enum bit-fields like enums,
not like bit-fields.
We used to get this right "by accident", because conversions for the
selected built-in overloaded operator would convert the enum bit-field
to its corresponding underlying type early. But after DR1687 that no
longer happens.
Technically this change should also apply to C, where bit-fields only
have special promotion rules if the bit-field's declared type is
_Bool, int, signed int, or unsigned int, but for GCC compatibility we
only look at the bit-width and not the underlying type when performing
bit-field integral promotions in C.
llvm-svn: 335925
Diffstat (limited to 'clang/lib/Sema/SemaOverload.cpp')
-rw-r--r-- | clang/lib/Sema/SemaOverload.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index e9d2eb6cc5c..6f01f19fc51 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -2007,6 +2007,14 @@ bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) { isCompleteType(From->getLocStart(), FromType)) return Context.hasSameUnqualifiedType( ToType, FromEnumType->getDecl()->getPromotionType()); + + // C++ [conv.prom]p5: + // If the bit-field has an enumerated type, it is treated as any other + // value of that type for promotion purposes. + // + // ... so do not fall through into the bit-field checks below in C++. + if (getLangOpts().CPlusPlus) + return false; } // C++0x [conv.prom]p2: @@ -2054,6 +2062,11 @@ bool Sema::IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType) { // other value of that type for promotion purposes (C++ 4.5p3). // FIXME: We should delay checking of bit-fields until we actually perform the // conversion. + // + // FIXME: In C, only bit-fields of types _Bool, int, or unsigned int may be + // promoted, per C11 6.3.1.1/2. We promote all bit-fields (including enum + // bit-fields and those whose underlying type is larger than int) for GCC + // compatibility. if (From) { if (FieldDecl *MemberDecl = From->getSourceBitField()) { llvm::APSInt BitWidth; |