[PATCH] D140280: [llvm] Fix APInt to work in C++20 mode
Joe Loser via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 18 20:20:37 PST 2022
jloser created this revision.
jloser added reviewers: MaskRay, dblaikie, kazu.
Herald added a subscriber: StephenFan.
Herald added a project: All.
jloser requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Currently, an `APSInt` test fails to compile in C++20 mode due to ambiguity in
the available set of `operator==` thanks to synthetic three-way rewrite rules.
Specifically, the error is:
error: use of overloaded operator '==' is ambiguous
(with operand types 'const llvm::APSInt' and 'const unsigned long long')
from llvm/unittests/ADT/APFixedPointTest.cpp:698:3:
note: in instantiation of function template specialization
'testing::internal::EqHelper::Compare<llvm::APSInt, unsigned long long, nullptr>' requested here
ASSERT_EQ(Val.convert(getLFractSema()).getValue(), -(1ULL << 31));
^
The candidates are:
llvm/include/llvm/ADT/APInt.h:2032:13: note: candidate function (with reversed parameter order)
inline bool operator==(uint64_t V1, const APInt &V2) { return V2 == V1; }
^
llvm/include/llvm/ADT/APSInt.h:174:8: note: candidate function
bool operator==(int64_t RHS) const {
^
llvm/include/llvm/ADT/APSInt.h:343:13: note: candidate function (with reversed parameter order)
inline bool operator==(int64_t V1, const APSInt &V2) { return V2 == V1; }
Make this case unambiguous by gating the extra `operator==` and `operator!=` on
the existence of three way comparison feature test macro.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D140280
Files:
llvm/include/llvm/ADT/APInt.h
Index: llvm/include/llvm/ADT/APInt.h
===================================================================
--- llvm/include/llvm/ADT/APInt.h
+++ llvm/include/llvm/ADT/APInt.h
@@ -2027,9 +2027,11 @@
/// @}
};
+#if !(__cplusplus > 201703L && __cpp_impl_three_way_comparison >= 201907L)
inline bool operator==(uint64_t V1, const APInt &V2) { return V2 == V1; }
inline bool operator!=(uint64_t V1, const APInt &V2) { return V2 != V1; }
+#endif
/// Unary bitwise complement operator.
///
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140280.483856.patch
Type: text/x-patch
Size: 495 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221219/4576423b/attachment.bin>
More information about the llvm-commits
mailing list