Avoid top level const for function parameters in function declarations

This rule exists as a check in clang-tidy see https://clang.llvm.org/extra/clang-tidy/checks/readability/avoid-const-params-in-decls.html

A function that takes it parameter by value will have the same type signature whether the parameter is declared const or not.

As a consequence, you can have this:

void func(int arg);

void func(const int arg)
{   
}

Which is completely fine. Often the function declaration is in a header file and the function definition is in a source file, but the important part is that the function has a declaration that is separate from the function definition.

However

void func(const int arg);

Is not compliant. The const is redundant and should be removed.

Hello @torgeir.skogen,

Indeed, this rule makes sense. Thanks for pointing it out!
I have created a ticket CPP-4096 to add it to our products.

Have a nice day,
Amélie

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.