summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-03-28 00:31:40 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-03-28 00:31:40 +0000
commitac8c17533f5dd20f31440d3f0ae253b9f6f50205 (patch)
tree4f7438bc083beb841df38d1ab49cbb0f743a874a
parent034f627838398568d1a12ac8d5a20eda04f54728 (diff)
downloadbcm5719-llvm-ac8c17533f5dd20f31440d3f0ae253b9f6f50205.tar.gz
bcm5719-llvm-ac8c17533f5dd20f31440d3f0ae253b9f6f50205.zip
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. llvm-svn: 233457
-rw-r--r--clang/lib/Sema/SemaOverload.cpp6
-rw-r--r--clang/test/SemaCXX/enum-bitfield.cpp8
2 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index fbf110b321e..cf84f23baf4 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/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/clang/test/SemaCXX/enum-bitfield.cpp b/clang/test/SemaCXX/enum-bitfield.cpp
index ec849b79a74..676ae44b37f 100644
--- a/clang/test/SemaCXX/enum-bitfield.cpp
+++ b/clang/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);
OpenPOWER on IntegriCloud