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 18: Generated C++ spaceship operator triggers clang-tidy warning #93409

Closed
pkl97 opened this issue May 26, 2024 · 3 comments · Fixed by #94512
Closed

clang 18: Generated C++ spaceship operator triggers clang-tidy warning #93409

pkl97 opened this issue May 26, 2024 · 3 comments · Fixed by #94512
Assignees
Labels
c++20 clang-tidy false-positive Warning fires when it should not

Comments

@pkl97
Copy link

pkl97 commented May 26, 2024

This program triggers a readability-implicit-bool-conversion clang-tidy warning:

#include <compare>
#include <list>

struct X
{
    auto operator<=>(const X&) const = default;
    bool m_b;
};

struct Y
{
    auto operator<=>(const Y&) const = default;
    std::list<X> m_xlist;
};

int main()
{
    return 0;
}

The warning emitted is the following:

main.cpp:6:46: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion]
    6 |     auto operator<=>(const X&) const = default;
      |                                              ^
      |                                              static_cast<int>( )

The clang-tidy command used:

clang-tidy --checks=-*,readability-implicit-bool-conversion main.cpp

It is somewhat unfortunate that a generated function triggers such a warning. Of course one can add NOLINT() statements to all affected operators but that unnecessarily clutters the code and makes it harder to read.

Is it possible to alter the generated code and avoid this warning?

@github-actions github-actions bot added clang Clang issues not falling into any other category clang-tidy labels May 26, 2024
@PiotrZSL
Copy link
Member

No, check need to be fixed.

@pkl97
Copy link
Author

pkl97 commented May 26, 2024

Of course, this would also be okay.

I just thought it would be better to fix the root cause and not the resulting symptom.
But the readability aim of the check is questionable here anyway because the generated spaceship operator is not visible to the developer.

@EugeneZelenko EugeneZelenko added c++20 false-positive Warning fires when it should not and removed clang Clang issues not falling into any other category labels May 26, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 26, 2024

@llvm/issue-subscribers-c-20

Author: None (pkl97)

This program triggers a readability-implicit-bool-conversion clang-tidy warning: ```c++ #include <compare> #include <list>

struct X
{
auto operator<=>(const X&) const = default;
bool m_b;
};

struct Y
{
auto operator<=>(const Y&) const = default;
std::list<X> m_xlist;
};

int main()
{
return 0;
}


The warning emitted is the following:
```bash
main.cpp:6:46: warning: implicit conversion 'bool' -&gt; 'int' [readability-implicit-bool-conversion]
    6 |     auto operator&lt;=&gt;(const X&amp;) const = default;
      |                                              ^
      |                                              static_cast&lt;int&gt;( )

The clang-tidy command used:

clang-tidy --checks=-*,readability-implicit-bool-conversion main.cpp

It is somewhat unfortunate that a generated function triggers such a warning. Of course one can add NOLINT() statements to all affected operators but that unnecessarily clutters the code and makes it harder to read.

Is it possible to alter the generated code and avoid this warning?

@PiotrZSL PiotrZSL self-assigned this May 30, 2024
PiotrZSL added a commit to PiotrZSL/llvm-project that referenced this issue Jun 5, 2024
…onversion

Ignore implicit declarations and defaulted functions.
Helps with issues in generated code like, C++
spaceship operator.

Closes llvm#93409
PiotrZSL added a commit that referenced this issue Jun 9, 2024
…onversion (#94512)

Ignore implicit declarations and defaulted functions. Helps with issues
in generated code like, C++
spaceship operator.

Closes #93409
nekoshirro pushed a commit to nekoshirro/Alchemist-LLVM that referenced this issue Jun 9, 2024
…onversion (llvm#94512)

Ignore implicit declarations and defaulted functions. Helps with issues
in generated code like, C++
spaceship operator.

Closes llvm#93409

Signed-off-by: Hafidz Muzakky <ais.muzakky@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang-tidy false-positive Warning fires when it should not
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@PiotrZSL @EugeneZelenko @pkl97 @llvmbot and others