| 1 |
.. title:: clang-tidy - readability-redundant-access-specifiers |
| 2 |
|
| 3 |
readability-redundant-access-specifiers |
| 4 |
======================================= |
| 5 |
|
| 6 |
Finds classes, structs, and unions containing redundant member (field and |
| 7 |
method) access specifiers. |
| 8 |
|
| 9 |
Example |
| 10 |
------- |
| 11 |
|
| 12 |
.. code-block:: c++ |
| 13 |
|
| 14 |
class Foo { |
| 15 |
public: |
| 16 |
int x; |
| 17 |
int y; |
| 18 |
public: |
| 19 |
int z; |
| 20 |
protected: |
| 21 |
int a; |
| 22 |
public: |
| 23 |
int c; |
| 24 |
} |
| 25 |
|
| 26 |
In the example above, the second ``public`` declaration can be removed without |
| 27 |
any changes of behavior. |
| 28 |
|
| 29 |
Options |
| 30 |
------- |
| 31 |
|
| 32 |
.. option:: CheckFirstDeclaration |
| 33 |
|
| 34 |
If set to `true`, the check will also diagnose if the first access |
| 35 |
specifier declaration is redundant (e.g. ``private`` inside ``class``, |
| 36 |
or ``public`` inside ``struct`` or ``union``). |
| 37 |
Default is `false`. |
| 38 |
|
| 39 |
Example |
| 40 |
^^^^^^^ |
| 41 |
|
| 42 |
.. code-block:: c++ |
| 43 |
|
| 44 |
struct Bar { |
| 45 |
public: |
| 46 |
int x; |
| 47 |
} |
| 48 |
|
| 49 |
If `CheckFirstDeclaration` option is enabled, a warning about redundant |
| 50 |
access specifier will be emitted, because ``public`` is the default member access |
| 51 |
for structs. |