summaryrefslogtreecommitdiff
path: root/test/SemaCXX
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2017-12-20 22:04:54 +0000
committerAaron Ballman <aaron@aaronballman.com>2017-12-20 22:04:54 +0000
commitbfdec8d00b2b4b35a86ab75d4265772f6f7da518 (patch)
treecc66aac08c4c13cadcc2f72b3209d1c353b15b5b /test/SemaCXX
parent1c11a98e84f2d2ca40b963cb0b2511eddbef963f (diff)
Add a printing policy to the ASTDumper.
This allows you to dump C++ code that spells bool instead of _Bool, leaves off the elaborated type specifiers when printing struct or class names, and other C-isms. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@321223 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX')
-rw-r--r--test/SemaCXX/compound-literal.cpp196
-rw-r--r--test/SemaCXX/sourceranges.cpp104
-rw-r--r--test/SemaCXX/warn-redundant-move.cpp232
3 files changed, 266 insertions, 266 deletions
diff --git a/test/SemaCXX/compound-literal.cpp b/test/SemaCXX/compound-literal.cpp
index 5480b1fef4..be9ebee00c 100644
--- a/test/SemaCXX/compound-literal.cpp
+++ b/test/SemaCXX/compound-literal.cpp
@@ -1,98 +1,98 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c++03 -verify -ast-dump %s > %t-03
-// RUN: FileCheck --input-file=%t-03 %s
-// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -ast-dump %s > %t-11
-// RUN: FileCheck --input-file=%t-11 %s
-// RUN: FileCheck --input-file=%t-11 %s --check-prefix=CHECK-CXX11
-
-// http://llvm.org/PR7905
-namespace PR7905 {
-struct S; // expected-note {{forward declaration}}
-void foo1() {
- (void)(S[]) {{3}}; // expected-error {{array has incomplete element type}}
-}
-
-template <typename T> struct M { T m; };
-void foo2() {
- (void)(M<short> []) {{3}};
-}
-}
-
-// Check compound literals mixed with C++11 list-initialization.
-namespace brace_initializers {
- struct POD {
- int x, y;
- };
- struct HasCtor {
- HasCtor(int x, int y);
- };
- struct HasDtor {
- int x, y;
- ~HasDtor();
- };
- struct HasCtorDtor {
- HasCtorDtor(int x, int y);
- ~HasCtorDtor();
- };
-
- void test() {
- (void)(POD){1, 2};
- // CHECK-NOT: CXXBindTemporaryExpr {{.*}} 'struct brace_initializers::POD'
- // CHECK: CompoundLiteralExpr {{.*}} 'struct brace_initializers::POD'
- // CHECK-NEXT: InitListExpr {{.*}} 'struct brace_initializers::POD'
- // CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}}
- // CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}}
-
- (void)(HasDtor){1, 2};
- // CHECK: CXXBindTemporaryExpr {{.*}} 'struct brace_initializers::HasDtor'
- // CHECK-NEXT: CompoundLiteralExpr {{.*}} 'struct brace_initializers::HasDtor'
- // CHECK-NEXT: InitListExpr {{.*}} 'struct brace_initializers::HasDtor'
- // CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}}
- // CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}}
-
-#if __cplusplus >= 201103L
- (void)(HasCtor){1, 2};
- // CHECK-CXX11-NOT: CXXBindTemporaryExpr {{.*}} 'struct brace_initializers::HasCtor'
- // CHECK-CXX11: CompoundLiteralExpr {{.*}} 'struct brace_initializers::HasCtor'
- // CHECK-CXX11-NEXT: CXXTemporaryObjectExpr {{.*}} 'struct brace_initializers::HasCtor'
- // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 1{{$}}
- // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 2{{$}}
-
- (void)(HasCtorDtor){1, 2};
- // CHECK-CXX11: CXXBindTemporaryExpr {{.*}} 'struct brace_initializers::HasCtorDtor'
- // CHECK-CXX11-NEXT: CompoundLiteralExpr {{.*}} 'struct brace_initializers::HasCtorDtor'
- // CHECK-CXX11-NEXT: CXXTemporaryObjectExpr {{.*}} 'struct brace_initializers::HasCtorDtor'
- // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 1{{$}}
- // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 2{{$}}
-#endif
- }
-
- struct PrivateDtor {
- int x, y;
- private:
- ~PrivateDtor(); // expected-note {{declared private here}}
- };
-
- void testPrivateDtor() {
- (void)(PrivateDtor){1, 2}; // expected-error {{temporary of type 'brace_initializers::PrivateDtor' has private destructor}}
- }
-}
-
-// This doesn't necessarily need to be an error, but CodeGen can't handle it
-// at the moment.
-int PR17415 = (int){PR17415}; // expected-error {{initializer element is not a compile-time constant}}
-
-// Make sure we accept this. (Not sure if we actually should... but we do
-// at the moment.)
-template<unsigned> struct Value { };
-template<typename T>
-int &check_narrowed(Value<sizeof((T){1.1})>);
-
-#if __cplusplus >= 201103L
-// Compound literals in global lambdas have automatic storage duration
-// and are not subject to the constant-initialization rules.
-int computed_with_lambda = [] {
- int x = 5;
- int result = ((int[]) { x, x + 2, x + 4, x + 6 })[0];
- return result;
-}();
-#endif
+// RUN: %clang_cc1 -fsyntax-only -std=c++03 -verify -ast-dump %s > %t-03
+// RUN: FileCheck --input-file=%t-03 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -ast-dump %s > %t-11
+// RUN: FileCheck --input-file=%t-11 %s
+// RUN: FileCheck --input-file=%t-11 %s --check-prefix=CHECK-CXX11
+
+// http://llvm.org/PR7905
+namespace PR7905 {
+struct S; // expected-note {{forward declaration}}
+void foo1() {
+ (void)(S[]) {{3}}; // expected-error {{array has incomplete element type}}
+}
+
+template <typename T> struct M { T m; };
+void foo2() {
+ (void)(M<short> []) {{3}};
+}
+}
+
+// Check compound literals mixed with C++11 list-initialization.
+namespace brace_initializers {
+ struct POD {
+ int x, y;
+ };
+ struct HasCtor {
+ HasCtor(int x, int y);
+ };
+ struct HasDtor {
+ int x, y;
+ ~HasDtor();
+ };
+ struct HasCtorDtor {
+ HasCtorDtor(int x, int y);
+ ~HasCtorDtor();
+ };
+
+ void test() {
+ (void)(POD){1, 2};
+ // CHECK-NOT: CXXBindTemporaryExpr {{.*}} 'brace_initializers::POD'
+ // CHECK: CompoundLiteralExpr {{.*}} 'brace_initializers::POD'
+ // CHECK-NEXT: InitListExpr {{.*}} 'brace_initializers::POD'
+ // CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}}
+ // CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}}
+
+ (void)(HasDtor){1, 2};
+ // CHECK: CXXBindTemporaryExpr {{.*}} 'brace_initializers::HasDtor'
+ // CHECK-NEXT: CompoundLiteralExpr {{.*}} 'brace_initializers::HasDtor'
+ // CHECK-NEXT: InitListExpr {{.*}} 'brace_initializers::HasDtor'
+ // CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}}
+ // CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}}
+
+#if __cplusplus >= 201103L
+ (void)(HasCtor){1, 2};
+ // CHECK-CXX11-NOT: CXXBindTemporaryExpr {{.*}} 'brace_initializers::HasCtor'
+ // CHECK-CXX11: CompoundLiteralExpr {{.*}} 'brace_initializers::HasCtor'
+ // CHECK-CXX11-NEXT: CXXTemporaryObjectExpr {{.*}} 'brace_initializers::HasCtor'
+ // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 1{{$}}
+ // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 2{{$}}
+
+ (void)(HasCtorDtor){1, 2};
+ // CHECK-CXX11: CXXBindTemporaryExpr {{.*}} 'brace_initializers::HasCtorDtor'
+ // CHECK-CXX11-NEXT: CompoundLiteralExpr {{.*}} 'brace_initializers::HasCtorDtor'
+ // CHECK-CXX11-NEXT: CXXTemporaryObjectExpr {{.*}} 'brace_initializers::HasCtorDtor'
+ // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 1{{$}}
+ // CHECK-CXX11-NEXT: IntegerLiteral {{.*}} 2{{$}}
+#endif
+ }
+
+ struct PrivateDtor {
+ int x, y;
+ private:
+ ~PrivateDtor(); // expected-note {{declared private here}}
+ };
+
+ void testPrivateDtor() {
+ (void)(PrivateDtor){1, 2}; // expected-error {{temporary of type 'brace_initializers::PrivateDtor' has private destructor}}
+ }
+}
+
+// This doesn't necessarily need to be an error, but CodeGen can't handle it
+// at the moment.
+int PR17415 = (int){PR17415}; // expected-error {{initializer element is not a compile-time constant}}
+
+// Make sure we accept this. (Not sure if we actually should... but we do
+// at the moment.)
+template<unsigned> struct Value { };
+template<typename T>
+int &check_narrowed(Value<sizeof((T){1.1})>);
+
+#if __cplusplus >= 201103L
+// Compound literals in global lambdas have automatic storage duration
+// and are not subject to the constant-initialization rules.
+int computed_with_lambda = [] {
+ int x = 5;
+ int result = ((int[]) { x, x + 2, x + 4, x + 6 })[0];
+ return result;
+}();
+#endif
diff --git a/test/SemaCXX/sourceranges.cpp b/test/SemaCXX/sourceranges.cpp
index 2f8eb2f2b9..287925f7ff 100644
--- a/test/SemaCXX/sourceranges.cpp
+++ b/test/SemaCXX/sourceranges.cpp
@@ -1,52 +1,52 @@
-// RUN: %clang_cc1 -triple i686-mingw32 -ast-dump %s | FileCheck %s
-
-template<class T>
-class P {
- public:
- P(T* t) {}
-};
-
-namespace foo {
-class A { public: A(int = 0) {} };
-enum B {};
-typedef int C;
-}
-
-// CHECK: VarDecl {{0x[0-9a-fA-F]+}} <line:16:1, col:36> col:15 ImplicitConstrArray 'foo::A [2]'
-static foo::A ImplicitConstrArray[2];
-
-int main() {
- // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::A *'
- P<foo::A> p14 = new foo::A;
- // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::B *'
- P<foo::B> p24 = new foo::B;
- // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::C *'
- P<foo::C> pr4 = new foo::C;
-}
-
-foo::A getName() {
- // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:10, col:17> 'foo::A'
- return foo::A();
-}
-
-void destruct(foo::A *a1, foo::A *a2, P<int> *p1) {
- // CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:8> '<bound member function type>' ->~A
- a1->~A();
- // CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:16> '<bound member function type>' ->~A
- a2->foo::A::~A();
- // CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:13> '<bound member function type>' ->~P
- p1->~P<int>();
-}
-
-struct D {
- D(int);
- ~D();
-};
-
-void construct() {
- using namespace foo;
- A a = A(12);
- // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'class foo::A' 'void (int){{( __attribute__\(\(thiscall\)\))?}}'
- D d = D(12);
- // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'struct D' 'void (int){{( __attribute__\(\(thiscall\)\))?}}'
-}
+// RUN: %clang_cc1 -triple i686-mingw32 -ast-dump %s | FileCheck %s
+
+template<class T>
+class P {
+ public:
+ P(T* t) {}
+};
+
+namespace foo {
+class A { public: A(int = 0) {} };
+enum B {};
+typedef int C;
+}
+
+// CHECK: VarDecl {{0x[0-9a-fA-F]+}} <line:16:1, col:36> col:15 ImplicitConstrArray 'foo::A [2]'
+static foo::A ImplicitConstrArray[2];
+
+int main() {
+ // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::A *'
+ P<foo::A> p14 = new foo::A;
+ // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::B *'
+ P<foo::B> p24 = new foo::B;
+ // CHECK: CXXNewExpr {{0x[0-9a-fA-F]+}} <col:19, col:28> 'foo::C *'
+ P<foo::C> pr4 = new foo::C;
+}
+
+foo::A getName() {
+ // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:10, col:17> 'foo::A'
+ return foo::A();
+}
+
+void destruct(foo::A *a1, foo::A *a2, P<int> *p1) {
+ // CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:8> '<bound member function type>' ->~A
+ a1->~A();
+ // CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:16> '<bound member function type>' ->~A
+ a2->foo::A::~A();
+ // CHECK: MemberExpr {{0x[0-9a-fA-F]+}} <col:3, col:13> '<bound member function type>' ->~P
+ p1->~P<int>();
+}
+
+struct D {
+ D(int);
+ ~D();
+};
+
+void construct() {
+ using namespace foo;
+ A a = A(12);
+ // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'foo::A' 'void (int){{( __attribute__\(\(thiscall\)\))?}}'
+ D d = D(12);
+ // CHECK: CXXConstructExpr {{0x[0-9a-fA-F]+}} <col:9, col:13> 'D' 'void (int){{( __attribute__\(\(thiscall\)\))?}}'
+}
diff --git a/test/SemaCXX/warn-redundant-move.cpp b/test/SemaCXX/warn-redundant-move.cpp
index abfb001fa8..2bfc8c9312 100644
--- a/test/SemaCXX/warn-redundant-move.cpp
+++ b/test/SemaCXX/warn-redundant-move.cpp
@@ -1,116 +1,116 @@
-// RUN: %clang_cc1 -fsyntax-only -Wredundant-move -std=c++11 -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wredundant-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
-// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -ast-dump | FileCheck %s --check-prefix=CHECK-AST
-
-// definitions for std::move
-namespace std {
-inline namespace foo {
-template <class T> struct remove_reference { typedef T type; };
-template <class T> struct remove_reference<T&> { typedef T type; };
-template <class T> struct remove_reference<T&&> { typedef T type; };
-
-template <class T> typename remove_reference<T>::type &&move(T &&t);
-}
-}
-
-// test1 and test2 should not warn until after implementation of DR1579.
-struct A {};
-struct B : public A {};
-
-A test1(B b1) {
- B b2;
- return b1;
- return b2;
- return std::move(b1);
- return std::move(b2);
-}
-
-struct C {
- C() {}
- C(A) {}
-};
-
-C test2(A a1, B b1) {
- A a2;
- B b2;
-
- return a1;
- return a2;
- return b1;
- return b2;
-
- return std::move(a1);
- return std::move(a2);
- return std::move(b1);
- return std::move(b2);
-}
-
-// Copy of tests above with types changed to reference types.
-A test3(B& b1) {
- B& b2 = b1;
- return b1;
- return b2;
- return std::move(b1);
- return std::move(b2);
-}
-
-C test4(A& a1, B& b1) {
- A& a2 = a1;
- B& b2 = b1;
-
- return a1;
- return a2;
- return b1;
- return b2;
-
- return std::move(a1);
- return std::move(a2);
- return std::move(b1);
- return std::move(b2);
-}
-
-// PR23819, case 2
-struct D {};
-D test5(D d) {
- return d;
- // Verify the implicit move from the AST dump
- // CHECK-AST: ReturnStmt{{.*}}line:[[@LINE-2]]
- // CHECK-AST-NEXT: CXXConstructExpr{{.*}}struct D{{.*}}void (struct D &&)
- // CHECK-AST-NEXT: ImplicitCastExpr
- // CHECK-AST-NEXT: DeclRefExpr{{.*}}ParmVar{{.*}}'d'
-
- return std::move(d);
- // expected-warning@-1{{redundant move in return statement}}
- // expected-note@-2{{remove std::move call here}}
- // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
- // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:21-[[@LINE-4]]:22}:""
-}
-
-namespace templates {
- struct A {};
- struct B { B(A); };
-
- // Warn once here since the type is not dependent.
- template <typename T>
- A test1(A a) {
- return std::move(a);
- // expected-warning@-1{{redundant move in return statement}}
- // expected-note@-2{{remove std::move call here}}
- // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:22}:""
- // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:23-[[@LINE-4]]:24}:""
- }
- void run_test1() {
- test1<A>(A());
- test1<B>(A());
- }
-
- // T1 and T2 may not be the same, the warning may not always apply.
- template <typename T1, typename T2>
- T1 test2(T2 t) {
- return std::move(t);
- }
- void run_test2() {
- test2<A, A>(A());
- test2<B, A>(A());
- }
-}
+// RUN: %clang_cc1 -fsyntax-only -Wredundant-move -std=c++11 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wredundant-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -ast-dump | FileCheck %s --check-prefix=CHECK-AST
+
+// definitions for std::move
+namespace std {
+inline namespace foo {
+template <class T> struct remove_reference { typedef T type; };
+template <class T> struct remove_reference<T&> { typedef T type; };
+template <class T> struct remove_reference<T&&> { typedef T type; };
+
+template <class T> typename remove_reference<T>::type &&move(T &&t);
+}
+}
+
+// test1 and test2 should not warn until after implementation of DR1579.
+struct A {};
+struct B : public A {};
+
+A test1(B b1) {
+ B b2;
+ return b1;
+ return b2;
+ return std::move(b1);
+ return std::move(b2);
+}
+
+struct C {
+ C() {}
+ C(A) {}
+};
+
+C test2(A a1, B b1) {
+ A a2;
+ B b2;
+
+ return a1;
+ return a2;
+ return b1;
+ return b2;
+
+ return std::move(a1);
+ return std::move(a2);
+ return std::move(b1);
+ return std::move(b2);
+}
+
+// Copy of tests above with types changed to reference types.
+A test3(B& b1) {
+ B& b2 = b1;
+ return b1;
+ return b2;
+ return std::move(b1);
+ return std::move(b2);
+}
+
+C test4(A& a1, B& b1) {
+ A& a2 = a1;
+ B& b2 = b1;
+
+ return a1;
+ return a2;
+ return b1;
+ return b2;
+
+ return std::move(a1);
+ return std::move(a2);
+ return std::move(b1);
+ return std::move(b2);
+}
+
+// PR23819, case 2
+struct D {};
+D test5(D d) {
+ return d;
+ // Verify the implicit move from the AST dump
+ // CHECK-AST: ReturnStmt{{.*}}line:[[@LINE-2]]
+ // CHECK-AST-NEXT: CXXConstructExpr{{.*}}D{{.*}}void (D &&)
+ // CHECK-AST-NEXT: ImplicitCastExpr
+ // CHECK-AST-NEXT: DeclRefExpr{{.*}}ParmVar{{.*}}'d'
+
+ return std::move(d);
+ // expected-warning@-1{{redundant move in return statement}}
+ // expected-note@-2{{remove std::move call here}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:10-[[@LINE-3]]:20}:""
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:21-[[@LINE-4]]:22}:""
+}
+
+namespace templates {
+ struct A {};
+ struct B { B(A); };
+
+ // Warn once here since the type is not dependent.
+ template <typename T>
+ A test1(A a) {
+ return std::move(a);
+ // expected-warning@-1{{redundant move in return statement}}
+ // expected-note@-2{{remove std::move call here}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:22}:""
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:23-[[@LINE-4]]:24}:""
+ }
+ void run_test1() {
+ test1<A>(A());
+ test1<B>(A());
+ }
+
+ // T1 and T2 may not be the same, the warning may not always apply.
+ template <typename T1, typename T2>
+ T1 test2(T2 t) {
+ return std::move(t);
+ }
+ void run_test2() {
+ test2<A, A>(A());
+ test2<B, A>(A());
+ }
+}