llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-tidy] false positive on cppcoreguidelines-missing-std-forward with constrained templates

Open rdong8 opened this issue 9 months ago • 3 comments

#include <concepts>

class A
{
public:
    template <std::derived_from<A> Self>
    auto operator|(this Self &&self, int) -> void {}
};

auto main() -> int
{
    A a;
    a | 1;
}

Self is a regular rvalue reference and not a forwarding reference in A::operator| because of the constraint (and as seen by the compiler error in main), but clang-tidy will still warn cppcoreguidelines-missing-std-forward on this.

rdong8 avatar Feb 07 '26 18:02 rdong8

@llvm/issue-subscribers-clang-tidy

Author: None (rdong8)

```cpp #include <concepts>

class A { public: template <std::derived_from<A> Self> auto operator|(this Self &&self, int) -> void {} };

auto main() -> int { A a; a | 1; }


`Self` is a regular rvalue reference and not a forwarding reference in `A::operator|` because of the constraint (and as seen by the compiler error in `main`), but clang-tidy will still warn [cppcoreguidelines-missing-std-forward](https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/missing-std-forward.html) on this.
</details>

llvmbot avatar Feb 07 '26 18:02 llvmbot

I had like to work on this. Will submit a PR shortly.

Aditya26189 avatar Feb 18 '26 14:02 Aditya26189

I have no idea about fixing it gracefully. It's hard to tell if a type satisfying a concept is always non-reference.

zwuis avatar Feb 18 '26 15:02 zwuis