1 | // RUN: %check_clang_tidy -std=c++17 %s modernize-use-designated-initializers %t \ |
2 | // RUN: -- \ |
3 | // RUN: -- -fno-delayed-template-parsing |
4 | // RUN: %check_clang_tidy -check-suffixes=,SINGLE-ELEMENT -std=c++17 %s modernize-use-designated-initializers %t \ |
5 | // RUN: -- -config="{CheckOptions: {modernize-use-designated-initializers.IgnoreSingleElementAggregates: false}}" \ |
6 | // RUN: -- -fno-delayed-template-parsing |
7 | // RUN: %check_clang_tidy -check-suffixes=POD -std=c++17 %s modernize-use-designated-initializers %t \ |
8 | // RUN: -- -config="{CheckOptions: {modernize-use-designated-initializers.RestrictToPODTypes: true}}" \ |
9 | // RUN: -- -fno-delayed-template-parsing |
10 | // RUN: %check_clang_tidy -check-suffixes=,MACROS -std=c++17 %s modernize-use-designated-initializers %t \ |
11 | // RUN: -- -config="{CheckOptions: {modernize-use-designated-initializers.IgnoreMacros: false}}" \ |
12 | // RUN: -- -fno-delayed-template-parsing |
13 | |
14 | struct S1 {}; |
15 | |
16 | S1 s11{}; |
17 | S1 s12 = {}; |
18 | S1 s13(); |
19 | S1 s14; |
20 | |
21 | struct S2 { int i, j; }; |
22 | |
23 | S2 s21{.i=1, .j =2}; |
24 | |
25 | S2 s22 = {.i: 1, .j: 2}; |
26 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use designated initializer list to initialize 'S2' [modernize-use-designated-initializers] |
27 | // CHECK-MESSAGES: :[[@LINE-6]]:1: note: aggregate type is defined here |
28 | // CHECK-MESSAGES-POD: :[[@LINE-3]]:10: warning: use designated initializer list to initialize 'S2' [modernize-use-designated-initializers] |
29 | // CHECK-MESSAGES-POD: :[[@LINE-8]]:1: note: aggregate type is defined here |
30 | // CHECK-FIXES: S2 s22 = {.i=1, .j=2}; |
31 | |
32 | S2 s23{.i: 1}; |
33 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use designated initializer list to initialize 'S2' [modernize-use-designated-initializers] |
34 | // CHECK-MESSAGES: :[[@LINE-13]]:1: note: aggregate type is defined here |
35 | // CHECK-MESSAGES-POD: :[[@LINE-3]]:7: warning: use designated initializer list to initialize 'S2' [modernize-use-designated-initializers] |
36 | // CHECK-MESSAGES-POD: :[[@LINE-15]]:1: note: aggregate type is defined here |
37 | // CHECK-FIXES: S2 s23{.i=1}; |
38 | |
39 | S2 s24{.i = 1}; |
40 | |
41 | S2 s25 = {.i=1, .j: 2}; |
42 | // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use designated init expression to initialize field 'j' [modernize-use-designated-initializers] |
43 | // CHECK-MESSAGES-POD: :[[@LINE-2]]:17: warning: use designated init expression to initialize field 'j' [modernize-use-designated-initializers] |
44 | // CHECK-FIXES: S2 s25 = {.i=1, .j=2}; |
45 | |
46 | class S3 { |
47 | public: |
48 | S2 s2; |
49 | double d; |
50 | }; |
51 | |
52 | S3 s31 = {.s2 = 1, .s2.j: 2, .d: 3.1}; |
53 | // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use designated init expression to initialize field 's2.j' [modernize-use-designated-initializers] |
54 | // CHECK-MESSAGES: :[[@LINE-2]]:23: warning: use designated init expression to initialize field 'd' [modernize-use-designated-initializers] |
55 | // CHECK-MESSAGES-POD: :[[@LINE-3]]:20: warning: use designated init expression to initialize field 's2.j' [modernize-use-designated-initializers] |
56 | // CHECK-MESSAGES-POD: :[[@LINE-4]]:23: warning: use designated init expression to initialize field 'd' [modernize-use-designated-initializers] |
57 | // CHECK-FIXES: S3 s31 = {.s2 = 1, .s2.j=2, .d=3.1}; |
58 | |
59 | S3 s32 = {.s2: {.i = 1, .j: 2}}; |
60 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use designated initializer list to initialize 'S3' [modernize-use-designated-initializers] |
61 | // CHECK-MESSAGES: :[[@LINE-15]]:1: note: aggregate type is defined here |
62 | // CHECK-MESSAGES: :[[@LINE-3]]:20: warning: use designated init expression to initialize field 'j' [modernize-use-designated-initializers] |
63 | // CHECK-MESSAGES-POD: :[[@LINE-4]]:10: warning: use designated initializer list to initialize 'S3' [modernize-use-designated-initializers] |
64 | // CHECK-MESSAGES-POD: :[[@LINE-18]]:1: note: aggregate type is defined here |
65 | // CHECK-MESSAGES-POD: :[[@LINE-6]]:20: warning: use designated init expression to initialize field 'j' [modernize-use-designated-initializers] |
66 | // CHECK-FIXES: S3 s32 = {.s2={.i = 1, .j=2}}; |
67 | |
68 | S3 s33 = {.s2: {.i: 2}, .d=3.1}; |
69 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use designated init expression to initialize field 's2' [modernize-use-designated-initializers] |
70 | // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: use designated initializer list to initialize 'S2' [modernize-use-designated-initializers] |
71 | // CHECK-MESSAGES: :[[@LINE-50]]:1: note: aggregate type is defined here |
72 | // CHECK-MESSAGES-POD: :[[@LINE-4]]:11: warning: use designated init expression to initialize field 's2' [modernize-use-designated-initializers] |
73 | // CHECK-MESSAGES-POD: :[[@LINE-5]]:11: warning: use designated initializer list to initialize 'S2' [modernize-use-designated-initializers] |
74 | // CHECK-MESSAGES-POD: :[[@LINE-53]]:1: note: aggregate type is defined here |
75 | // CHECK-FIXES: S3 s33 = {.s2={.i=2}, .d=3.1}; |
76 | |
77 | struct S4 { |
78 | double d; |
79 | private: static int i; |
80 | }; |
81 | |
82 | S4 s41 {.d: 2.2}; |
83 | // CHECK-MESSAGES-SINGLE-ELEMENT: :[[@LINE-1]]:8: warning: use designated initializer list to initialize 'S4' [modernize-use-designated-initializers] |
84 | // CHECK-MESSAGES-SINGLE-ELEMENT: :[[@LINE-7]]:1: note: aggregate type is defined here |
85 | // CHECK-FIXES-SINGLE-ELEMENT: S4 s41 {.d=2.2}; |
86 | |
87 | S4 s42 = {.d: {}}; |
88 | // CHECK-MESSAGES-SINGLE-ELEMENT: :[[@LINE-1]]:10: warning: use designated initializer list to initialize 'S4' [modernize-use-designated-initializers] |
89 | // CHECK-MESSAGES-SINGLE-ELEMENT: :[[@LINE-12]]:1: note: aggregate type is defined here |
90 | // CHECK-FIXES-SINGLE-ELEMENT: S4 s42 = {.d={}}; |
91 | |
92 | template<typename S> S template1() { return {10, 11}; } |
93 | |
94 | S2 s26 = template1<S2>(); |
95 | |
96 | template<typename S> S template2() { return {}; } |
97 | |
98 | S2 s27 = template2<S2>(); |
99 | |
100 | struct S5: S2 { int x, y; }; |
101 | |
102 | S5 s51 {1, 2, .x = 3, .y = 4}; |
103 | |
104 | struct S6 { |
105 | int i; |
106 | struct { int j; } s; |
107 | }; |
108 | |
109 | S6 s61 {.i: 1, .s.j: 2}; |
110 | // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use designated initializer list to initialize 'S6' [modernize-use-designated-initializers] |
111 | // CHECK-MESSAGES: :[[@LINE-7]]:1: note: aggregate type is defined here |
112 | // CHECK-MESSAGES-POD: :[[@LINE-3]]:8: warning: use designated initializer list to initialize 'S6' [modernize-use-designated-initializers] |
113 | // CHECK-MESSAGES-POD: :[[@LINE-9]]:1: note: aggregate type is defined here |
114 | // CHECK-FIXES: S6 s61 {.i=1, .s.j=2}; |
115 | |
116 | struct S7 { |
117 | union { |
118 | int k; |
119 | double d; |
120 | } u; |
121 | }; |
122 | |
123 | S7 s71 {.u.k: 1}; |
124 | // CHECK-MESSAGES-SINGLE-ELEMENT: :[[@LINE-1]]:8: warning: use designated initializer list to initialize 'S7' [modernize-use-designated-initializers] |
125 | // CHECK-MESSAGES-SINGLE-ELEMENT: :[[@LINE-9]]:1: note: aggregate type is defined here |
126 | // CHECK-FIXES-SINGLE-ELEMENT: S7 s71 {.u.k=1}; |
127 | |
128 | struct S8: S7 { int i; }; |
129 | |
130 | S8 s81{1, .i: 2}; |
131 | |
132 | struct S9 { |
133 | int i, j; |
134 | S9 &operator=(S9); |
135 | }; |
136 | |
137 | S9 s91{.i: 1, .j: 2}; |
138 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use designated initializer list to initialize 'S9' [modernize-use-designated-initializers] |
139 | // CHECK-MESSAGES: :[[@LINE-7]]:1: note: aggregate type is defined here |
140 | // CHECK-FIXES: S9 s91{.i=1, .j=2}; |
141 | |
142 | struct S10 { int i = 1, j = 2; }; |
143 | |
144 | S10 s101 {.i: 1, .j=2}; |
145 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use designated init expression to initialize field 'i' [modernize-use-designated-initializers] |
146 | // CHECK-FIXES: S10 s101 {.i=1, .j=2}; |
147 | |
148 | struct S11 { int i; S10 s10; }; |
149 | |
150 | S11 s111 { .i = 1 }; |
151 | S11 s112 { .i: 1 }; |
152 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use designated initializer list to initialize 'S11' [modernize-use-designated-initializers] |
153 | // CHECK-MESSAGES: :[[@LINE-5]]:1: note: aggregate type is defined here |
154 | // CHECK-FIXES: S11 s112 { .i=1 }; |
155 | |
156 | S11 s113 { .i=1, .s10: {}}; |
157 | // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use designated init expression to initialize field 's10' [modernize-use-designated-initializers] |
158 | // CHECK-FIXES: S11 s113 { .i=1, .s10={}}; |
159 | |
160 | S11 s114 { .i=1, .s10={.i: 1, .j=2}}; |
161 | // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use designated init expression to initialize field 'i' [modernize-use-designated-initializers] |
162 | // CHECK-FIXES: S11 s114 { .i=1, .s10={.i=1, .j=2}}; |
163 | |
164 | struct S12 { |
165 | int i; |
166 | struct { int j; }; |
167 | }; |
168 | |
169 | S12 s121 {.i: 1, .j: 2}; |
170 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use designated initializer list to initialize 'S12' [modernize-use-designated-initializers] |
171 | // CHECK-MESSAGES: :[[@LINE-7]]:1: note: aggregate type is defined here |
172 | // CHECK-MESSAGES-POD: :[[@LINE-3]]:10: warning: use designated initializer list to initialize 'S12' [modernize-use-designated-initializers] |
173 | // CHECK-MESSAGES-POD: :[[@LINE-9]]:1: note: aggregate type is defined here |
174 | // CHECK-FIXES: S12 s121 {.i=1, .j=2}; |
175 | |
176 | struct S13 { |
177 | union { |
178 | int k; |
179 | double d; |
180 | }; |
181 | int i; |
182 | }; |
183 | |
184 | S13 s131 {.k: 1, .i: 2}; |
185 | // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use designated initializer list to initialize 'S13' [modernize-use-designated-initializers] |
186 | // CHECK-MESSAGES: :[[@LINE-10]]:1: note: aggregate type is defined here |
187 | // CHECK-MESSAGES-POD: :[[@LINE-3]]:10: warning: use designated initializer list to initialize 'S13' [modernize-use-designated-initializers] |
188 | // CHECK-MESSAGES-POD: :[[@LINE-12]]:1: note: aggregate type is defined here |
189 | // CHECK-FIXES: S13 s131 {.k=1, .i=2}; |
190 | |
191 | #define A (3+2) |
192 | #define B .j=1 |
193 | |
194 | S9 s92 {A, B}; |
195 | // CHECK-MESSAGES-MACROS: :[[@LINE-1]]:9: warning: use designated init expression to initialize field 'i' [modernize-use-designated-initializers] |
196 | // CHECK-MESSAGES-MACROS: :[[@LINE-5]]:11: note: expanded from macro 'A' |
197 | |
198 | #define DECLARE_S93 S9 s93 {1, 2} |
199 | |
200 | DECLARE_S93; |
201 | // CHECK-MESSAGES-MACROS: :[[@LINE-1]]:1: warning: use designated initializer list to initialize 'S9' [modernize-use-designated-initializers] |
202 | // CHECK-MESSAGES-MACROS: :[[@LINE-4]]:28: note: expanded from macro 'DECLARE_S93' |
203 | // CHECK-MESSAGES-MACROS: :[[@LINE-71]]:1: note: aggregate type is defined here |
204 | |