Skip to content

Commit

Permalink
Don't cast out-of-enum-range -1 to CommonIntegralTypes
Browse files Browse the repository at this point in the history
This fixes the following Clang 16 compilation error:
kdevelop/plugins/clang/duchain/cursorkindtraits.h:217:7: error: integer value -1 is outside the valid range of values [0, 255] for the enumeration type 'CommonIntegralTypes' [-Wenum-constexpr-conversion]
    : static_cast<IntegralType::CommonIntegralTypes>(-1);

Quote from llvm/llvm-project#59036 :
    The -Wenum-constexpr-conversion warning was created to account for
    the fact that casting integers to enums outside of the valid range
    of the enum is UB in C++17. Constant expressions invoking UB lead to
    an ill-formed program.

BUG: 471995
FIXED-IN: 5.12.230800
  • Loading branch information
vedgy committed Jul 7, 2023
1 parent 071e47c commit ede1cf4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion kdevplatform/language/duchain/types/integraltype.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class KDEVPLATFORMLANGUAGE_EXPORT IntegralType
TypeChar16_t,
TypeChar32_t,
TypeHalf,
TypeLanguageSpecific = 200
TypeLanguageSpecific = 200,
TypeNotIntegralType = 255
};

/// Default constructor
Expand Down
2 changes: 1 addition & 1 deletion plugins/clang/duchain/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ struct Visitor
return context;
}

template<CXTypeKind TK, EnableIf<CursorKindTraits::integralType(TK) != -1> = dummy>
template<CXTypeKind TK, EnableIf<CursorKindTraits::integralType(TK) != IntegralType::TypeNotIntegralType> = dummy>
AbstractType *createType(CXType, CXCursor)
{
// TODO: would be nice to instantiate a ConstantIntegralType here and set a value if possible
Expand Down
2 changes: 1 addition & 1 deletion plugins/clang/duchain/cursorkindtraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ constexpr IntegralType::CommonIntegralTypes integralType(CXTypeKind TK)
||TK == CXType_Char_S
||TK == CXType_UChar
||TK == CXType_SChar) ? IntegralType::TypeChar
: static_cast<IntegralType::CommonIntegralTypes>(-1);
: IntegralType::TypeNotIntegralType;
}

constexpr bool isArrayType(CXTypeKind TK)
Expand Down

0 comments on commit ede1cf4

Please sign in to comment.