Skip to content

Commit 4d07c7f

Browse files
authored
[clang-tidy][NFC] fix compilation by disambiguating equality operator (#147048)
This fixes an issue compiling LLVM 20.1.7 on Ubuntu 22.04 with the Ubuntu provided Clang 14 and C++20. That's probably happening due to incomplete C++20 support in either Clang 14 or the GNU libstdc++ 12. The actual error is: ``` [1/8] Building CXX object tools/clang/tools/extra/clang-tidy/bugprone/CMakeFiles/obj.clangTidyBugproneModule.dir/TaggedUnionMemberCountCheck.cpp.o FAILED: tools/clang/tools/extra/clang-tidy/bugprone/CMakeFiles/obj.clangTidyBugproneModule.dir/TaggedUnionMemberCountCheck.cpp.o /usr/lib/llvm-14/bin/clang++ -DGTEST_HAS_RTTI=0 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/work/_build/tools/clang/tools/extra/clang-tidy/bugprone -I/work/llvm-project/clang-tools-extra/clang-tidy/bugprone -I/work/_build/tools/clang/tools/extra/clang-tidy -I/work/llvm-project/clang/include -I/work/_build/tools/clang/include -I/work/_build/include -I/work/llvm-project/llvm/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG -std=c++20 -fno-exceptions -funwind-tables -fno-rtti -MD -MT tools/clang/tools/extra/clang-tidy/bugprone/CMakeFiles/obj.clangTidyBugproneModule.dir/TaggedUnionMemberCountCheck.cpp.o -MF tools/clang/tools/extra/clang-tidy/bugprone/CMakeFiles/obj.clangTidyBugproneModule.dir/TaggedUnionMemberCountCheck.cpp.o.d -o tools/clang/tools/extra/clang-tidy/bugprone/CMakeFiles/obj.clangTidyBugproneModule.dir/TaggedUnionMemberCountCheck.cpp.o -c /work/llvm-project/clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp /work/llvm-project/clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp:148:39: error: use of overloaded operator '==' is ambiguous (with operand types 'llvm::APSInt' and 'unsigned long') (LastEnumConstant->getInitVal() == (EnumValues.size() - 1))) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~ /work/llvm-project/llvm/include/llvm/ADT/APInt.h:2080:13: note: candidate function (with reversed parameter order) inline bool operator==(uint64_t V1, const APInt &V2) { return V2 == V1; } ^ /work/llvm-project/llvm/include/llvm/ADT/APSInt.h:188:8: note: candidate function bool operator==(int64_t RHS) const { ^ /work/llvm-project/llvm/include/llvm/ADT/APSInt.h:357:13: note: candidate function (with reversed parameter order) inline bool operator==(int64_t V1, const APSInt &V2) { return V2 == V1; } ^ 1 error generated. ``` I know that clang-14 in combination with the GNU libstdc++ 12 might not be 100% C++20 compliant. But this is the only error we see when compiling LLVM 20.1.7 and it looks very fixable Thanks, Gregor --------- Signed-off-by: Gregor Jasny <gjasny@googlemail.com>
1 parent cd75c2f commit 4d07c7f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ TaggedUnionMemberCountCheck::getNumberOfEnumValues(const EnumDecl *ED) {
144144

145145
if (EnableCountingEnumHeuristic && LastEnumConstant &&
146146
isCountingEnumLikeName(LastEnumConstant->getName()) &&
147-
(LastEnumConstant->getInitVal() == (EnumValues.size() - 1))) {
147+
llvm::APSInt::isSameValue(LastEnumConstant->getInitVal(),
148+
llvm::APSInt::get(EnumValues.size() - 1))) {
148149
return {EnumValues.size() - 1, LastEnumConstant};
149150
}
150151

0 commit comments

Comments
 (0)