File tree 3 files changed +38
-3
lines changed
3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,9 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
279
279
hasParent (callExpr ()),
280
280
hasSourceExpression (binaryOperator (hasAnyOperatorName (" ==" , " !=" ))));
281
281
282
+ auto IsInCompilerGeneratedFunction = hasAncestor (namedDecl (anyOf (
283
+ isImplicit (), functionDecl (isDefaulted ()), functionTemplateDecl ())));
284
+
282
285
Finder->addMatcher (
283
286
traverse (TK_AsIs,
284
287
implicitCastExpr (
@@ -299,7 +302,7 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
299
302
// additional parens in replacement.
300
303
optionally (hasParent (stmt ().bind (" parentStmt" ))),
301
304
unless (isInTemplateInstantiation ()),
302
- unless (hasAncestor ( functionTemplateDecl ()) ))
305
+ unless (IsInCompilerGeneratedFunction ))
303
306
.bind (" implicitCastToBool" )),
304
307
this );
305
308
@@ -331,7 +334,7 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
331
334
anyOf (hasParent (implicitCastExpr ().bind (" furtherImplicitCast" )),
332
335
anything ()),
333
336
unless (isInTemplateInstantiation ()),
334
- unless (hasAncestor ( functionTemplateDecl ()) ))),
337
+ unless (IsInCompilerGeneratedFunction ))),
335
338
this );
336
339
}
337
340
Original file line number Diff line number Diff line change @@ -408,7 +408,8 @@ Changes in existing checks
408
408
valid fix suggestions for ``static_cast `` without a preceding space and
409
409
fixed problem with duplicate parentheses in double implicit casts. Corrected
410
410
the fix suggestions for C23 and later by using C-style casts instead of
411
- ``static_cast ``.
411
+ ``static_cast ``. Fixed false positives in C++20 spaceship operator by ignoring
412
+ casts in implicit and defaulted functions.
412
413
413
414
- Improved :doc: `readability-redundant-inline-specifier
414
415
<clang-tidy/checks/readability/redundant-inline-specifier>` check to properly
Original file line number Diff line number Diff line change
1
+ // RUN: %check_clang_tidy -std=c++20 %s readability-implicit-bool-conversion %t
2
+
3
+ namespace std {
4
+ struct strong_ordering {
5
+ int n;
6
+ constexpr operator int () const { return n; }
7
+ static const strong_ordering equal, greater, less;
8
+ };
9
+ constexpr strong_ordering strong_ordering::equal = {0 };
10
+ constexpr strong_ordering strong_ordering::greater = {1 };
11
+ constexpr strong_ordering strong_ordering::less = {-1 };
12
+ } // namespace std
13
+
14
+ namespace PR93409 {
15
+ struct X
16
+ {
17
+ auto operator <=>(const X&) const = default ;
18
+ bool m_b;
19
+ };
20
+
21
+ struct Y
22
+ {
23
+ auto operator <=>(const Y&) const = default ;
24
+ X m_x;
25
+ };
26
+
27
+ bool compare (const Y& y1, const Y& y2)
28
+ {
29
+ return y1 == y2 || y1 < y2 || y1 > y2;
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments