Skip to content

Clang-tidy: modernize-use-nullptr produces a false-positive on std:: strong_ordering (spaceship operator result) #63478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fastasturtle opened this issue Jun 23, 2023 · 4 comments
Assignees
Labels
clang-tidy false-positive Warning fires when it should not

Comments

@fastasturtle
Copy link

fastasturtle commented Jun 23, 2023

#include <compare>

int main() {
    auto res = 0 <=> 1;
    if (res < 0) {} // warning: use nullptr [modernize-use-nullptr]
}

https://gcc.godbolt.org/z/89W17v8j7

@EugeneZelenko EugeneZelenko added clang-tidy false-positive Warning fires when it should not and removed new issue labels Jun 23, 2023
@llvmbot
Copy link
Member

llvmbot commented Jun 23, 2023

@llvm/issue-subscribers-clang-tidy

@PiotrZSL
Copy link
Member

I'm not sure if this is false positive, simply if you put there any other number than 0, it wont compile, and in AST this 0 is implicit casted to pointer during construction of __cmp_cat::__unspec.

@fastasturtle
Copy link
Author

I'm not sure if this is false positive, simply if you put there any other number than 0, it wont compile, and in AST this 0 is implicit casted to pointer during construction of __cmp_cat::__unspec.

@PiotrZSL while this is technically possible to use nullptr instead of 0, the comparison operator return value result is expected to be compared with 0 (similar to the return value of strcpy, etc) - see e.g. the original proposal.

The way it's worded in the standard is (if I'm reading it correctly) is here: https://eel.is/c++draft/cmp#categories.pre-3

@PiotrZSL
Copy link
Member

@PiotrZSL PiotrZSL added the awaiting-review Has pending Phabricator review label Aug 26, 2023
@PiotrZSL PiotrZSL removed the awaiting-review Has pending Phabricator review label Sep 10, 2023
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this issue Sep 19, 2023
New option added and configured in a way, so types
related to std::strong_ordering would be ignored.

Fixes: llvm#63478

Reviewed By: ccotter

Differential Revision: https://reviews.llvm.org/D158928
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-tidy false-positive Warning fires when it should not
Projects
None yet
Development

No branches or pull requests

4 participants