[clang-tidy] fix modernize-use-nullptr false positive with spaceship operator comparisons
authorpoelmanc <cpllvm@stellarscience.com>
Tue, 9 Feb 2021 14:02:12 +0000 (14:02 +0000)
committerNathan James <n.james93@hotmail.co.uk>
Tue, 9 Feb 2021 14:02:45 +0000 (14:02 +0000)
commit98146c1f5d0c772aec56149724119d49990f4d0c
treec76eaa93f23769d154f8918764828bd35b03d374
parent068bf9e80220329f7baeaf8df34fb4818ad8aa58
[clang-tidy] fix modernize-use-nullptr false positive with spaceship operator comparisons

`clang-tidy -std=c++20` with `modernize-use-nullptr` mistakenly inserts `nullptr` in place of the comparison operator if the comparison internally expands in the AST to a rewritten spaceship operator. This can be reproduced by running the new `modernize-use-nullptr-cxx20.cpp` test without applying the supplied patch to `UseNullptrCheck.cpp`; the current clang-tidy will mistakenly replace:
```result = (a1 < a2);```
with
```result = (a1 nullptr a2);```

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D95714
clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-cxx20.cpp [new file with mode: 0644]