summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/test')
-rw-r--r--clang-tools-extra/test/CMakeLists.txt1
-rw-r--r--clang-tools-extra/test/clang-reorder-fields/AggregatePartialInitialization.cpp14
-rw-r--r--clang-tools-extra/test/clang-reorder-fields/CStructAmbiguousName.cpp18
-rw-r--r--clang-tools-extra/test/clang-reorder-fields/CStructFieldsOrder.cpp16
-rw-r--r--clang-tools-extra/test/clang-reorder-fields/ClassDifferentFieldsAccesses.cpp16
-rw-r--r--clang-tools-extra/test/clang-reorder-fields/ClassMixedInitialization.cpp24
-rw-r--r--clang-tools-extra/test/clang-reorder-fields/ClassSimpleCtor.cpp24
7 files changed, 113 insertions, 0 deletions
diff --git a/clang-tools-extra/test/CMakeLists.txt b/clang-tools-extra/test/CMakeLists.txt
index 22ee4ee56dd..228076cc609 100644
--- a/clang-tools-extra/test/CMakeLists.txt
+++ b/clang-tools-extra/test/CMakeLists.txt
@@ -45,6 +45,7 @@ set(CLANG_TOOLS_TEST_DEPS
clang-include-fixer
clang-query
clang-rename
+ clang-reorder-fields
clang-tidy
find-all-symbols
modularize
diff --git a/clang-tools-extra/test/clang-reorder-fields/AggregatePartialInitialization.cpp b/clang-tools-extra/test/clang-reorder-fields/AggregatePartialInitialization.cpp
new file mode 100644
index 00000000000..9d09c818775
--- /dev/null
+++ b/clang-tools-extra/test/clang-reorder-fields/AggregatePartialInitialization.cpp
@@ -0,0 +1,14 @@
+// RUN: clang-reorder-fields -record-name Foo -fields-order z,y,x %s -- | FileCheck %s
+
+// The order of fields should not change.
+class Foo {
+public:
+ int x; // CHECK: {{^ int x;}}
+ int y; // CHECK-NEXT: {{^ int y;}}
+ int z; // CHECK-NEXT: {{^ int z;}}
+};
+
+int main() {
+ Foo foo = { 0, 1 }; // CHECK: {{^ Foo foo = { 0, 1 };}}
+ return 0;
+}
diff --git a/clang-tools-extra/test/clang-reorder-fields/CStructAmbiguousName.cpp b/clang-tools-extra/test/clang-reorder-fields/CStructAmbiguousName.cpp
new file mode 100644
index 00000000000..e1e6645511d
--- /dev/null
+++ b/clang-tools-extra/test/clang-reorder-fields/CStructAmbiguousName.cpp
@@ -0,0 +1,18 @@
+// RUN: clang-reorder-fields -record-name ::Foo -fields-order y,x %s -- | FileCheck %s
+
+struct Foo {
+ int x; // CHECK: {{^ double y;}}
+ double y; // CHECK-NEXT: {{^ int x;}}
+};
+
+namespace bar {
+struct Foo {
+ int x; // CHECK: {{^ int x;}}
+ double y; // CHECK-NEXT: {{^ double y;}}
+};
+} // end namespace bar
+
+int main() {
+ bar::Foo foo = { 1, 1.7 }; // CHECK: {{^ bar::Foo foo = { 1, 1.7 };}}
+ return 0;
+}
diff --git a/clang-tools-extra/test/clang-reorder-fields/CStructFieldsOrder.cpp b/clang-tools-extra/test/clang-reorder-fields/CStructFieldsOrder.cpp
new file mode 100644
index 00000000000..2ed3578df65
--- /dev/null
+++ b/clang-tools-extra/test/clang-reorder-fields/CStructFieldsOrder.cpp
@@ -0,0 +1,16 @@
+// RUN: clang-reorder-fields -record-name ::bar::Foo -fields-order z,w,y,x %s -- | FileCheck %s
+
+namespace bar {
+struct Foo {
+ const int* x; // CHECK: {{^ double z;}}
+ int y; // CHECK-NEXT: {{^ int w;}}
+ double z; // CHECK-NEXT: {{^ int y;}}
+ int w; // CHECK-NEXT: {{^ const int\* x}}
+};
+} // end namespace bar
+
+int main() {
+ const int x = 13;
+ bar::Foo foo = { &x, 0, 1.29, 17 }; // CHECK: {{^ bar::Foo foo = { 1.29, 17, 0, &x };}}
+ return 0;
+}
diff --git a/clang-tools-extra/test/clang-reorder-fields/ClassDifferentFieldsAccesses.cpp b/clang-tools-extra/test/clang-reorder-fields/ClassDifferentFieldsAccesses.cpp
new file mode 100644
index 00000000000..dd0a555a815
--- /dev/null
+++ b/clang-tools-extra/test/clang-reorder-fields/ClassDifferentFieldsAccesses.cpp
@@ -0,0 +1,16 @@
+// RUN: clang-reorder-fields -record-name Foo -fields-order z,y,x %s -- | FileCheck %s
+
+// The order of fields should not change.
+class Foo {
+public:
+ int x; // CHECK: {{^ int x;}}
+
+private:
+ int y; // CHECK: {{^ int y;}}
+ int z; // CHECK-NEXT: {{^ int z;}}
+};
+
+int main() {
+ Foo foo;
+ return 0;
+}
diff --git a/clang-tools-extra/test/clang-reorder-fields/ClassMixedInitialization.cpp b/clang-tools-extra/test/clang-reorder-fields/ClassMixedInitialization.cpp
new file mode 100644
index 00000000000..888649a9120
--- /dev/null
+++ b/clang-tools-extra/test/clang-reorder-fields/ClassMixedInitialization.cpp
@@ -0,0 +1,24 @@
+// RUN: clang-reorder-fields -record-name Foo -fields-order e,x,pi,s2,s1 %s -- -std=c++11 | FileCheck %s
+
+class Foo {
+public:
+ Foo();
+
+private:
+ int x; // CHECK: {{^ double e = 2.71;}}
+ const char *s1; // CHECK-NEXT: {{^ int x;}}
+ const char *s2; // CHECK-NEXT: {{^ double pi = 3.14;}}
+ double pi = 3.14; // CHECK-NEXT: {{^ const char \*s2;}}
+ double e = 2.71; // CHECK-NEXT: {{^ const char \*s1;}}
+};
+
+Foo::Foo():
+ x(12), // CHECK: {{^ x\(12\)}},
+ s1("abc"), // CHECK-NEXT: {{^ s2\("def"\)}},
+ s2("def") // CHECK-NEXT: {{^ s1\("abc"\)}}
+{}
+
+int main() {
+ Foo foo;
+ return 0;
+}
diff --git a/clang-tools-extra/test/clang-reorder-fields/ClassSimpleCtor.cpp b/clang-tools-extra/test/clang-reorder-fields/ClassSimpleCtor.cpp
new file mode 100644
index 00000000000..6dc27222a58
--- /dev/null
+++ b/clang-tools-extra/test/clang-reorder-fields/ClassSimpleCtor.cpp
@@ -0,0 +1,24 @@
+// RUN: clang-reorder-fields -record-name Foo -fields-order s1,x,z,s2 %s -- | FileCheck %s
+
+class Foo {
+public:
+ Foo();
+
+private:
+ int x; // CHECK: {{^ const char \*s1;}}
+ const char *s1; // CHECK-NEXT: {{^ int x;}}
+ const char *s2; // CHECK-NEXT: {{^ double z;}}
+ double z; // CHECK-NEXT: {{^ const char \*s2;}}
+};
+
+Foo::Foo():
+ x(12), // CHECK: {{^ s1\("abc"\),}}
+ s1("abc"), // CHECK-NEXT: {{^ x\(12\),}}
+ s2("def"), // CHECK-NEXT: {{^ z\(3.14\),}}
+ z(3.14) // CHECK-NEXT: {{^ s2\("def"\)}}
+{}
+
+int main() {
+ Foo foo;
+ return 0;
+}
OpenPOWER on IntegriCloud