1// RUN: clang-reorder-fields -record-name bar::Foo -fields-order y,z,c,x %s -- 2>&1 | FileCheck --check-prefix=CHECK-MESSAGES %s
2// FIXME: clang-reorder-fields should provide -verify mode to make writing these checks
3// easier and more accurate, for now we follow clang-tidy's approach.
4
5namespace bar {
6
7struct Dummy {
8 Dummy(int x, char c) : x(x), c(c) {}
9 int x;
10 char c;
11};
12
13class Foo {
14public:
15 Foo(int x, double y, char cin);
16 Foo(int nx);
17 Foo();
18 int x;
19 double y;
20 char c;
21 Dummy z;
22};
23
24static char bar(char c) {
25 return c + 1;
26}
27
28Foo::Foo() : x(), y(), c(), z(0, 'a') {}
29
30Foo::Foo(int x, double y, char cin) :
31 x(x),
32 y(y),
33 c(cin),
34 z(this->x, bar(c))
35 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: reordering field x after z makes x uninitialized when used in init expression
36 // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: reordering field c after z makes c uninitialized when used in init expression
37{}
38
39Foo::Foo(int nx) :
40 x(nx),
41 y(x),
42 c(0),
43 z(bar(c: bar(c: x)), c)
44 // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: reordering field x after y makes x uninitialized when used in init expression
45 // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: reordering field x after z makes x uninitialized when used in init expression
46 // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: reordering field c after z makes c uninitialized when used in init expression
47{}
48
49} // namespace bar
50
51int main() {
52 bar::Foo F(5, 12.8, 'c');
53 return 0;
54}
55

source code of clang-tools-extra/test/clang-reorder-fields/FieldDependencyWarning.cpp