| 1 |
.. title:: clang-tidy - readability-inconsistent-declaration-parameter-name |
| 2 |
|
| 3 |
readability-inconsistent-declaration-parameter-name |
| 4 |
=================================================== |
| 5 |
|
| 6 |
Find function declarations which differ in parameter names. |
| 7 |
|
| 8 |
Example: |
| 9 |
|
| 10 |
.. code-block:: c++ |
| 11 |
|
| 12 |
// in foo.hpp: |
| 13 |
void foo(int a, int b, int c); |
| 14 |
|
| 15 |
// in foo.cpp: |
| 16 |
void foo(int d, int e, int f); // warning |
| 17 |
|
| 18 |
This check should help to enforce consistency in large projects, where it often |
| 19 |
happens that a definition of function is refactored, changing the parameter |
| 20 |
names, but its declaration in header file is not updated. With this check, we |
| 21 |
can easily find and correct such inconsistencies, keeping declaration and |
| 22 |
definition always in sync. |
| 23 |
|
| 24 |
Unnamed parameters are allowed and are not taken into account when comparing |
| 25 |
function declarations, for example: |
| 26 |
|
| 27 |
.. code-block:: c++ |
| 28 |
|
| 29 |
void foo(int a); |
| 30 |
void foo(int); // no warning |
| 31 |
|
| 32 |
One name is also allowed to be a case-insensitive prefix/suffix of the other: |
| 33 |
|
| 34 |
.. code-block:: c++ |
| 35 |
|
| 36 |
void foo(int count); |
| 37 |
void foo(int count_input) { // no warning |
| 38 |
int count = adjustCount(count_input); |
| 39 |
} |
| 40 |
|
| 41 |
To help with refactoring, in some cases fix-it hints are generated to align |
| 42 |
parameter names to a single naming convention. This works with the assumption |
| 43 |
that the function definition is the most up-to-date version, as it directly |
| 44 |
references parameter names in its body. Example: |
| 45 |
|
| 46 |
.. code-block:: c++ |
| 47 |
|
| 48 |
void foo(int a); // warning and fix-it hint (replace "a" to "b") |
| 49 |
int foo(int b) { return b + 2; } // definition with use of "b" |
| 50 |
|
| 51 |
In the case of multiple redeclarations or function template specializations, |
| 52 |
a warning is issued for every redeclaration or specialization inconsistent with |
| 53 |
the definition or the first declaration seen in a translation unit. |
| 54 |
|
| 55 |
.. option:: IgnoreMacros |
| 56 |
|
| 57 |
If this option is set to `true` (default is `true`), the check will not warn |
| 58 |
about names declared inside macros. |
| 59 |
|
| 60 |
.. option:: Strict |
| 61 |
|
| 62 |
If this option is set to `true` (default is `false`), then names must match |
| 63 |
exactly (or be absent). |