[PATCH] D138701: [clang-tidy] Ignore cxxRewrittenBinaryOperator in defaulted function decls in modernize-use-nullptr.
Ilya Biryukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 25 06:46:35 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdb335d02a5e7: [clang-tidy] Ignore cxxRewrittenBinaryOperator in defaulted function decls in… (authored by massberg, committed by ilya-biryukov).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138701/new/
https://reviews.llvm.org/D138701
Files:
clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
@@ -1,9 +1,33 @@
// RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t
namespace std {
+class strong_ordering;
+
+// Mock how STD defined unspecified parameters for the operators below.
+struct _CmpUnspecifiedParam {
+ consteval
+ _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
+};
+
struct strong_ordering {
- int n;
- constexpr operator int() const { return n; }
+ signed char value;
+
+ friend constexpr bool operator==(strong_ordering v,
+ _CmpUnspecifiedParam) noexcept {
+ return v.value == 0;
+ }
+ friend constexpr bool operator<(strong_ordering v,
+ _CmpUnspecifiedParam) noexcept {
+ return v.value < 0;
+ }
+ friend constexpr bool operator>(strong_ordering v,
+ _CmpUnspecifiedParam) noexcept {
+ return v.value > 0;
+ }
+ friend constexpr bool operator>=(strong_ordering v,
+ _CmpUnspecifiedParam) noexcept {
+ return v.value >= 0;
+ }
static const strong_ordering equal, greater, less;
};
constexpr strong_ordering strong_ordering::equal = {0};
@@ -12,8 +36,10 @@
} // namespace std
class A {
+ int a;
public:
auto operator<=>(const A &other) const = default;
+ // CHECK-FIXES: auto operator<=>(const A &other) const = default;
};
void test_cxx_rewritten_binary_ops() {
@@ -32,3 +58,14 @@
result = (a1 > ((a1 > (ptr == 0 ? a1 : a2)) ? a1 : a2));
// CHECK-FIXES: result = (a1 > ((a1 > (ptr == nullptr ? a1 : a2)) ? a1 : a2));
}
+
+template<class T1, class T2>
+struct P {
+ T1 x1;
+ T2 x2;
+ friend auto operator<=>(const P&, const P&) = default;
+ // CHECK-FIXES: friend auto operator<=>(const P&, const P&) = default;
+};
+
+bool foo(P<int,int> x, P<int, int> y) { return x < y; }
+// CHECK-FIXES: bool foo(P<int,int> x, P<int, int> y) { return x < y; }
Index: clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -62,7 +62,9 @@
ImplicitCastToNull,
hasAncestor(cxxRewrittenBinaryOperator().bind(
"checkBinopOperands")))
- .bind(CastSequence))))));
+ .bind(CastSequence))),
+ // Skip defaulted comparison operators.
+ unless(hasAncestor(functionDecl(isDefaulted()))))));
}
bool isReplaceableRange(SourceLocation StartLoc, SourceLocation EndLoc,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138701.477948.patch
Type: text/x-patch
Size: 2948 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221125/d99d74b7/attachment-0001.bin>
More information about the cfe-commits
mailing list