Detect Non-static calls to static method [C++]

Hi

Is there a feature of reshaprer, to detect non-static calls of static-methods?

e.g. a class:

TestClass{
	//... some stuff
public:
	TestClass();
	static bool loadData(DataHolder& data);
	//... other stuff
}

And then:

//…
DataHolder a, b, c;
TestClass::loadData(a); //ok
TestClass()::loadData(b); //warning: Non-static call to a static method.
TestClass notNeeded; //if the warning below is resolved → not needed variable
notNeeded.loadData(c); //warning: Non-static call to a static method.
//…

If not, can I request this as a feature?

I know, that calls like these are allowed by the standards, but it would be nice for refactoring.

In my case I changed parts of the code and afterwards Resharper notified a lot of methods that they can be static now but I had to change the calls by myself.

Thanks!

1
2 comments

Though this will not help you, I'd like to share a somewhat unconventional naming convention I've employed over the years that has greatly aided in reasoning about code: global and static functions start with an Uppercase letter, while non-static class methods begin with a lowercase.

0

Hello,

If you're using clang-tidy integration of R#, there's the readability-static-accessed-through-instance check provided by clang-tidy, see the screenshot. You can enable the fix for this check in your code cleanup profile and then run code cleanup to fix the calls.

There's no built-in R# equivalent inspection yet. The feature request is RSCPP-5661.

0

Please sign in to leave a comment.