Skip to content
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

Clang-Tidy: modernize-use-nullptr does not make sense with spaceship operator #53961

Closed
pavelkryukov opened this issue Feb 20, 2022 · 6 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior c++20 clang-tidy confirmed Verified by a second party

Comments

@pavelkryukov
Copy link

pavelkryukov commented Feb 20, 2022

Reopening #45580, as the problem was not solved:

https://godbolt.org/z/3hed7vPvM

#include <compare>

struct A {
  int a;
  constexpr auto operator<=>(const A&) const = default;
};

bool foo(A x, A y) { return x < y; }

Command line:

clang-tidy-13 -checks='hicpp-use-nullptr' tidy20.cpp -- -std=c++20

Output:

<source>:5:56: warning: use nullptr [hicpp-use-nullptr]
    constexpr auto operator<=>(const A&) const = default;
                                                       ^
                                                        nullptr

Also, for strange reasons I cannot escape it with NOLINTNEXTLINE with local clang-tidy-13.
Godbolt's trunk version suppresses warning correctly.

@EugeneZelenko EugeneZelenko added bug Indicates an unexpected problem or unintended behavior c++20 clang-tidy and removed new issue labels Feb 20, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 20, 2022

@llvm/issue-subscribers-c-20

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 20, 2022

@llvm/issue-subscribers-bug

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 20, 2022

@llvm/issue-subscribers-clang-tidy

@JonasToth
Copy link
Member

JonasToth commented Feb 21, 2022

for the suppression: maybe this check is aliased, did you use NOLINTNEXTLINE(modernize-use-nullptr)? Aliased checks cause the warning to appear multiple times.

@pavelkryukov
Copy link
Author

pavelkryukov commented Feb 21, 2022

Yes, I did. It did not help :-(

@AaronBallman AaronBallman added the confirmed Verified by a second party label Feb 22, 2022
@jensmassberg
Copy link
Contributor

modernize-use-nullptr gives a warning for

#include <compare>

struct A {
  int a;
  constexpr auto operator<=>(const A&) const = default;
};

bool foo(A x, A y) { return x < y; }

but it doesn't warn for

#include <compare>

struct A {
  constexpr auto operator<=>(const A&) const = default;
};

bool foo(A x, A y) { return x < y; }

nor for

namespace std {
struct strong_ordering {
  int n;
  constexpr operator int() const { return n; }
  static const strong_ordering equal, greater, less;
};
constexpr strong_ordering strong_ordering::equal = {0};
constexpr strong_ordering strong_ordering::greater = {1};
constexpr strong_ordering strong_ordering::less = {-1};
} // namespace std

struct A {
  int a;
  constexpr auto operator<=>(const A&) const = default;
};

bool foo(A x, A y) { return x < y; }

The latter one is equivalent to the C++20 test for modernize-use-nullptr .

malavikasamak pushed a commit to apple/llvm-project that referenced this issue Dec 16, 2022
…decls in modernize-use-nullptr

The check has produced false positives when checking the default implementation of the spaceship operator.
The default implementation should be skipped by the check.

Modified the existing test so that the check runs into the bug without this fix and add another test case.

Fixes llvm#53961.

Patch by Jens Massberg.

Reviewed By: ilya-biryukov

Differential Revision: https://reviews.llvm.org/D138701

(cherry picked from commit db335d0)
ziqingluo-90 pushed a commit to ziqingluo-90/apple-llvm-project that referenced this issue Dec 17, 2022
…decls in modernize-use-nullptr

The check has produced false positives when checking the default implementation of the spaceship operator.
The default implementation should be skipped by the check.

Modified the existing test so that the check runs into the bug without this fix and add another test case.

Fixes llvm#53961.

Patch by Jens Massberg.

Reviewed By: ilya-biryukov

Differential Revision: https://reviews.llvm.org/D138701

(cherry picked from commit db335d0)
ziqingluo-90 pushed a commit to ziqingluo-90/apple-llvm-project that referenced this issue Dec 19, 2022
…decls in modernize-use-nullptr

The check has produced false positives when checking the default implementation of the spaceship operator.
The default implementation should be skipped by the check.

Modified the existing test so that the check runs into the bug without this fix and add another test case.

Fixes llvm#53961.

Patch by Jens Massberg.

Reviewed By: ilya-biryukov

Differential Revision: https://reviews.llvm.org/D138701

(cherry picked from commit db335d0)
ziqingluo-90 pushed a commit to ziqingluo-90/apple-llvm-project that referenced this issue Jan 5, 2023
…decls in modernize-use-nullptr

The check has produced false positives when checking the default implementation of the spaceship operator.
The default implementation should be skipped by the check.

Modified the existing test so that the check runs into the bug without this fix and add another test case.

Fixes llvm#53961.

Patch by Jens Massberg.

Reviewed By: ilya-biryukov

Differential Revision: https://reviews.llvm.org/D138701

(cherry picked from commit db335d0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior c++20 clang-tidy confirmed Verified by a second party
Projects
Status: Done
Development

No branches or pull requests

7 participants