[PATCH] D95714: clang-tidy: modernize-use-nullptr mistakenly fixes rewritten spaceship operator comparisons

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 30 09:01:28 PST 2021


njames93 added a comment.

Thanks for looking at this, its been on my todo list for long time.
Regarding the hasGrandparent idea, that could be recreated with `hasParent(expr(hasParent(cxxRewrittenBinaryOperator())))`
Though looking at the (trimmed) AST I'm not sure that's enough. Appears to have 4 levels of parents before reaching the cxxRewrittenBinaryOperator

  -CXXRewrittenBinaryOperator <col:13, col:18> 'bool'
    -CXXOperatorCallExpr <col:13, col:16> 'bool' '<' adl
     |-ImplicitCastExpr <col:16> 'bool (*)(std::strong_ordering, __cmp_cat::__unspec) noexcept' <FunctionToPointerDecay>
     |-CXXOperatorCallExpr <col:13, col:18> 'std::strong_ordering':'std::strong_ordering' '<=>'
      -ImplicitCastExpr <col:16> '__cmp_cat::__unspec':'std::__cmp_cat::__unspec' <ConstructorConversion>
        -CXXConstructExpr <col:16> '__cmp_cat::__unspec':'std::__cmp_cat::__unspec' 'void (std::__cmp_cat::__unspec *) noexcept'
          -ImplicitCastExpr <col:16> 'std::__cmp_cat::__unspec *' <NullToPointer> // Cast we care about
            -IntegerLiteral <col:16> 'int' 0



================
Comment at: clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-cxx20.cpp:3-4
+
+// Not all systems have #include <compare> to define std::std_ordering
+// required by operator<=>, so recreate minimal version for tests below.
+namespace std {
----------------
We don't compile against a std library for tests so this comment is redundant.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95714/new/

https://reviews.llvm.org/D95714



More information about the cfe-commits mailing list