| 1 |
.. title:: clang-tidy - modernize-use-default-member-init |
| 2 |
|
| 3 |
modernize-use-default-member-init |
| 4 |
================================= |
| 5 |
|
| 6 |
This check converts constructors' member initializers into the new |
| 7 |
default member initializers in C++11. Other member initializers that match the |
| 8 |
default member initializer are removed. This can reduce repeated code or allow |
| 9 |
use of '= default'. |
| 10 |
|
| 11 |
.. code-block:: c++ |
| 12 |
|
| 13 |
struct A { |
| 14 |
A() : i(5), j(10.0) {} |
| 15 |
A(int i) : i(i), j(10.0) {} |
| 16 |
int i; |
| 17 |
double j; |
| 18 |
}; |
| 19 |
|
| 20 |
// becomes |
| 21 |
|
| 22 |
struct A { |
| 23 |
A() {} |
| 24 |
A(int i) : i(i) {} |
| 25 |
int i{5}; |
| 26 |
double j{10.0}; |
| 27 |
}; |
| 28 |
|
| 29 |
.. note:: |
| 30 |
Only converts member initializers for built-in types, enums, and pointers. |
| 31 |
The `readability-redundant-member-init` check will remove redundant member |
| 32 |
initializers for classes. |
| 33 |
|
| 34 |
Options |
| 35 |
------- |
| 36 |
|
| 37 |
.. option:: UseAssignment |
| 38 |
|
| 39 |
If this option is set to `true` (default is `false`), the check will initialize |
| 40 |
members with an assignment. For example: |
| 41 |
|
| 42 |
.. code-block:: c++ |
| 43 |
|
| 44 |
struct A { |
| 45 |
A() {} |
| 46 |
A(int i) : i(i) {} |
| 47 |
int i = 5; |
| 48 |
double j = 10.0; |
| 49 |
}; |
| 50 |
|
| 51 |
.. option:: IgnoreMacros |
| 52 |
|
| 53 |
If this option is set to `true` (default is `true`), the check will not warn |
| 54 |
about members declared inside macros. |