llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.31k stars 12.11k forks source link

Bug with misc-unconventional-assign-operator in CRTP #115939

Open higher-performance opened 2 weeks ago

higher-performance commented 2 weeks ago

Clang-Tidy for

template <class Derived>
struct Crtp {
  Derived& operator=(decltype(nullptr)) {
    return *static_cast<Derived*>(this);
  };
};

struct S : Crtp<S> {
  using Crtp<S>::operator=;
};

should not produce

<source>:3:3: warning: operator=() should return 'Crtp&' [misc-unconventional-assign-operator]
    3 |   Derived& operator=(decltype(nullptr)) {
      |   ^

It should only flag assignments that are special member functions (i.e. copy- or move-assignments), not other assignments.

llvmbot commented 2 weeks ago

@llvm/issue-subscribers-clang-tidy

Author: None (higher-performance)

Clang-Tidy for ```c++ template <class Derived> struct Crtp { Derived& operator=(decltype(nullptr)) { return *static_cast<Derived*>(this); }; }; struct S : Crtp<S> { using Crtp<S>::operator=; }; ``` should not produce ``` <source>:3:3: warning: operator=() should return 'Crtp&' [misc-unconventional-assign-operator] 3 | Derived& operator=(decltype(nullptr)) { | ^ ``` It should only flag assignments that are special member functions (i.e. copy- or move-assignments), not other assignments.