3
3
modernize-use-designated-initializers
4
4
=====================================
5
5
6
- Finds initializer lists for aggregate type that could be written as
7
- designated initializers instead.
6
+ Finds initializer lists for aggregate types which could be written as designated
7
+ initializers instead.
8
8
9
- With plain initializer lists, it is very easy to introduce bugs when adding
10
- new fields in the middle of a struct or class type. The same confusion might
11
- arise when changing the order of fields.
9
+ With plain initializer lists, it is very easy to introduce bugs when adding new
10
+ fields in the middle of a struct or class type. The same confusion might arise
11
+ when changing the order of fields.
12
12
13
- C++20 supports the designated initializer syntax for aggregate types.
14
- By applying it, we can always be sure that aggregates are constructed correctly,
15
- because every variable being initialized is referenced by name.
16
-
17
- Even when compiling in a language version older than C++20, depending on your
18
- compiler, designated initializers are potentially supported. Therefore, the
19
- check is not restricted to C++20 and older. Check out the options
20
- ``-Wc99-designator `` to get support for mixed designators in
21
- initializer list in C and ``-Wc++20-designator `` for support of designated
22
- initializers in older C++ language modes.
13
+ C++20 supports the designated initializer syntax for aggregate types. By
14
+ applying it, we can always be sure that aggregates are constructed correctly,
15
+ because every variable being initialized is referenced by its name.
23
16
24
17
Example:
25
18
@@ -42,21 +35,28 @@ instead of
42
35
which could easily become an issue when ``i `` and ``j `` are swapped in the
43
36
declaration of ``S ``.
44
37
38
+ Even when compiling in a language version older than C++20, depending on your
39
+ compiler, designated initializers are potentially supported. Therefore, the
40
+ check is not restricted to C++20 and newer versions. Check out the options
41
+ ``-Wc99-designator `` to get support for mixed designators in initializer list in
42
+ C and ``-Wc++20-designator `` for support of designated initializers in older C++
43
+ language modes.
44
+
45
45
Options
46
46
-------
47
47
48
48
.. option :: IgnoreMacros
49
49
50
- The value `false ` specifies that components of initializer lists expanded
51
- from macros are not checked. The default value is `true `.
50
+ The value `false ` specifies that components of initializer lists expanded from
51
+ macros are not checked. The default value is `true `.
52
52
53
53
.. option :: IgnoreSingleElementAggregates
54
54
55
- The value `false ` specifies that even initializers for aggregate types
56
- with only a single element should be checked. The default value is `true `.
55
+ The value `false ` specifies that even initializers for aggregate types with
56
+ only a single element should be checked. The default value is `true `.
57
57
58
58
.. option :: RestrictToPODTypes
59
59
60
60
The value `true ` specifies that only Plain Old Data (POD) types shall be
61
- checked. This makes the check applicable to even older C++ standards.
62
- The default value is `false `.
61
+ checked. This makes the check applicable to even older C++ standards. The
62
+ default value is `false `.
0 commit comments