Open
Description
#include <print>
#include <string>
struct Hello {
std::string str_;
void hello(this Hello &self) { std::println("Hello, {0}!", self.str_); }
};
int main() {
Hello hi{"world"};
hi.hello();
return 0;
}
Saving this file as explicit_object_param.cpp
, I get
$ clang-tidy --checks=readability-convert-member-functions-to-static explicit_object_param.cpp -- --std=c++23
1 warning generated.
/home/chriselrod/Documents/progwork/cxx/misc/explicit_object_param.cpp:7:8: warning: method 'hello' can be made static [readability-convert-member-functions-to-static]
7 | void hello(this Hello &self) { std::println("Hello, {0}!", self.str_); }
| ^
| static
Of course, static
is illegal there
explicit_object_param.cpp:7:21: error: an explicit object parameter cannot appear in a static function
7 | static void hello(this Hello &self) { std::println("Hello, {0}!", self.str_); }
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
1 error generated.