In the process of automatically renaming many variables in a big project I may have created a lot of things like these:
class Foo {
int Par;
void Bar(int Par) {
Par = Par; // Nonsense
}
};
Now I need to identify those locations to correct them. E.g. into “this->Par = Par;”.
Unfortunately the Visual C++ Compiler des not give me any comment about it even with all warnings on.
I remember there once was a warning about it. It said “Code has no effect” or something. But it seems to be gone maybe because some people used that practice to avoid “unreferenced parameter” warnings.
Is there a way to re-activate that warning?
Does GCC warn here?
Any Idea?
A couple of compilers can generate warnings on this:
-Wshadowoption. (Specifically, while they don’t warn about the meaningless assignment, they do warn about the local variableParshadowing the member variablePar– you may or may not like this.)Par = Paris useless, but it can warn thatParisn’t used after it’s assigned to, which should meet your needs.I suspect a tool like PC-Lint could also identify code like this.
Another solution is to mark your parameters as
const:conston pass-by-value parameters is not part of the function signature, so you only need to add it to the function definitions within your.cppfile, not your function declarations within your.hfile. In other words, it’s legal to do this: