Skip to content

Commit

Permalink
Suppress Wsign-conversion for enums with matching underlying type
Browse files Browse the repository at this point in the history
As reported here: https://bugs.llvm.org/show_bug.cgi?id=34692

A non-defined enum with a backing type was always defaulting to
being treated as a signed type. IN the case where it IS defined,
the signed-ness of the actual items is used.

This patch uses the underlying type's signed-ness in the non-defined
case to test signed-comparision.

Differential Revision: https://reviews.llvm.org/D38145

llvm-svn: 313907
  • Loading branch information
Erich Keane committed Sep 21, 2017
1 parent 4fbaa62 commit 69dbbb0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clang/lib/Sema/SemaChecking.cpp
Expand Up @@ -8171,8 +8171,11 @@ struct IntRange {
// For enum types, use the known bit width of the enumerators.
if (const EnumType *ET = dyn_cast<EnumType>(T)) {
EnumDecl *Enum = ET->getDecl();
// In C++11, enums without definitions can have an explicitly specified
// underlying type. Use this type to compute the range.
if (!Enum->isCompleteDefinition())
return IntRange(C.getIntWidth(QualType(T, 0)), false);
return IntRange(C.getIntWidth(QualType(T, 0)),
!ET->isSignedIntegerOrEnumerationType());

unsigned NumPositive = Enum->getNumPositiveBits();
unsigned NumNegative = Enum->getNumNegativeBits();
Expand Down

0 comments on commit 69dbbb0

Please sign in to comment.