Add a readability-const-value-return check to clang-tidy.
Sometimes people qualify return types with const. This was always unnecessarily verbose, but in modern C++ it has an even worse side effect: it prevents moving the returned object (unless one defines a move assignment operator that takes a "const &&", which is an even worse idea).
For example:
#include <iostream> struct X { int a = 0; X& operator=(const X& other) { a = other.a; std::cout << "copied\n"; return *this; } X& operator=(X&& other) { a = other.a; std::cout << "moved\n"; return *this; } }; const X f_bad() { return {}; } X f_good() { return {}; } int main() { X x; x = f_bad(); x = f_good(); return 0; }
The assignment to x from f_bad forces a copy, while the assignment from f_good results in a move.
Therefore, it's better to avoid using const when returning things by value. This clang-tidy check warns about such situations.
The check ignores returns of const pointers (meaning * const, not const *); while pointless, these are not particularly harmful. It could be made laxer by ignoring all trivially copyable types (on the grounds that they won't have interesting move constructors/assigners anyway), or stricter by ignoring all const returns (on the grounds that, in the best case, it's just pointless verbosity). Or it could be made an option.
How about just matching definitions to avoid duplicate warnings?