summaryrefslogtreecommitdiff
path: root/clang/test/CXX/stmt.stmt
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/CXX/stmt.stmt')
-rw-r--r--clang/test/CXX/stmt.stmt/stmt.ambig/p1-0x.cpp40
-rw-r--r--clang/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp55
-rw-r--r--clang/test/CXX/stmt.stmt/stmt.dcl/p3.cpp47
-rw-r--r--clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp209
-rw-r--r--clang/test/CXX/stmt.stmt/stmt.label/p1.cpp25
-rw-r--r--clang/test/CXX/stmt.stmt/stmt.select/p3.cpp19
-rw-r--r--clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p2-0x.cpp39
7 files changed, 434 insertions, 0 deletions
diff --git a/clang/test/CXX/stmt.stmt/stmt.ambig/p1-0x.cpp b/clang/test/CXX/stmt.stmt/stmt.ambig/p1-0x.cpp
new file mode 100644
index 0000000..81e8e25
--- /dev/null
+++ b/clang/test/CXX/stmt.stmt/stmt.ambig/p1-0x.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+struct T {
+ struct x {
+ int m;
+ };
+ x* operator->();
+ void operator++(int);
+ void operator<<(int);
+ T();
+ T(int);
+ T(int, int);
+};
+
+template<typename A, typename B, typename C, typename D, typename E>
+void func(A, B, C, D, E);
+
+void func(int a, int c) {
+ T(a)->m = 7;
+ T(a)++;
+ T(a,5)<<c;
+
+ T(*d)(int);
+ T(e)[5];
+ T(f) = {1, 2};
+ T(*g)(double(3)); // expected-error{{cannot initialize a variable of type 'T (*)' with an rvalue of type 'double'}}
+ func(a, d, e, f, g);
+}
+
+void func2(int a, int c) {
+ decltype(T())(a)->m = 7;
+ decltype(T())(a)++;
+ decltype(T())(a,5)<<c;
+
+ decltype(T())(*d)(int);
+ decltype(T())(e)[5];
+ decltype(T())(f) = {1, 2};
+ decltype(T())(*g)(double(3)); // expected-error{{cannot initialize a variable of type 'decltype(T()) (*)' (aka 'T *') with an rvalue of type 'double'}}
+ func(a, d, e, f, g);
+}
diff --git a/clang/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp b/clang/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp
new file mode 100644
index 0000000..574cb40
--- /dev/null
+++ b/clang/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+// PR10034
+struct X {};
+
+void exx(X) {}
+
+int test_ptr10034(int argc, char **argv)
+{
+ if (argc > 3)
+ goto end;
+
+ X x;
+ X xs[16];
+ exx(x);
+
+ end:
+ if (argc > 1) {
+ for (int i = 0; i < argc; ++i)
+ {
+
+ }
+ }
+ return 0;
+}
+
+struct Y {
+ ~Y();
+};
+
+void f();
+void test_Y() {
+ goto end; // expected-error{{goto into protected scope}}
+ Y y; // expected-note{{jump bypasses variable with a non-trivial destructor}}
+ end:
+ f();
+ goto inner; // expected-error{{goto into protected scope}}
+ {
+ Y y2; // expected-note{{jump bypasses variable with a non-trivial destructor}}
+ inner:
+ f();
+ }
+ return;
+}
+
+struct Z {
+ Z operator=(const Z&);
+};
+
+void test_Z() {
+ goto end;
+ Z z;
+ end:
+ return;
+}
diff --git a/clang/test/CXX/stmt.stmt/stmt.dcl/p3.cpp b/clang/test/CXX/stmt.stmt/stmt.dcl/p3.cpp
new file mode 100644
index 0000000..f52e3b6
--- /dev/null
+++ b/clang/test/CXX/stmt.stmt/stmt.dcl/p3.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR10034
+struct X {};
+
+void exx(X) {}
+
+int test_ptr10034(int argc, char **argv)
+{
+ if (argc > 3)
+ goto end;
+
+ X x;
+ X xs[16];
+ exx(x);
+
+ end:
+ if (argc > 1) {
+ for (int i = 0; i < argc; ++i)
+ {
+
+ }
+ }
+ return 0;
+}
+
+struct Y {
+ ~Y();
+};
+
+void test_Y() {
+ goto end; // expected-error{{goto into protected scope}}
+ Y y; // expected-note{{jump bypasses variable with a non-trivial destructor}}
+ end:
+ return;
+}
+
+struct Z {
+ Z operator=(const Z&);
+};
+
+void test_Z() {
+ goto end; // expected-error{{goto into protected scope}}
+ Z z; // expected-note{{jump bypasses initialization of non-POD variable}}
+ end:
+ return;
+}
diff --git a/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp b/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
new file mode 100644
index 0000000..a45b35f
--- /dev/null
+++ b/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
@@ -0,0 +1,209 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+namespace std {
+ template<typename T>
+ auto begin(T &&t) -> decltype(t.begin()) { return t.begin(); } // expected-note 4{{ignored: substitution failure}}
+ template<typename T>
+ auto end(T &&t) -> decltype(t.end()) { return t.end(); } // expected-note {{candidate template ignored: substitution failure [with T = }}
+
+ template<typename T>
+ auto begin(T &&t) -> decltype(t.alt_begin()) { return t.alt_begin(); } // expected-note {{selected 'begin' template [with T = }} \
+ expected-note 4{{candidate template ignored: substitution failure [with T = }}
+ template<typename T>
+ auto end(T &&t) -> decltype(t.alt_end()) { return t.alt_end(); } // expected-note {{candidate template ignored: substitution failure [with T = }}
+
+ namespace inner {
+ // These should never be considered.
+ int begin(int);
+ int end(int);
+ }
+
+ using namespace inner;
+}
+
+struct A { // expected-note 2 {{candidate constructor}}
+ A();
+ int *begin(); // expected-note 3{{selected 'begin' function with iterator type 'int *'}} expected-note {{'begin' declared here}}
+ int *end();
+};
+
+struct B {
+ B();
+ int *alt_begin();
+ int *alt_end();
+};
+
+void f();
+void f(int);
+
+void g() {
+ for (int a : A())
+ A __begin;
+ for (char *a : A()) { // expected-error {{cannot initialize a variable of type 'char *' with an lvalue of type 'int'}}
+ }
+ for (char *a : B()) { // expected-error {{cannot initialize a variable of type 'char *' with an lvalue of type 'int'}}
+ }
+ // FIXME: Terrible diagnostic here. auto deduction should fail, but does not!
+ for (double a : f) { // expected-error {{cannot use type '<overloaded function type>' as a range}}
+ }
+ for (auto a : A()) {
+ }
+ for (auto a : B()) {
+ }
+ for (auto *a : A()) { // expected-error {{variable 'a' with type 'auto *' has incompatible initializer of type 'int'}}
+ }
+ // : is not a typo for :: here.
+ for (A NS:A()) { // expected-error {{no viable conversion from 'int' to 'A'}}
+ }
+ for (auto not_in_scope : not_in_scope) { // expected-error {{use of undeclared identifier 'not_in_scope'}}
+ }
+
+ for (auto a : A())
+ for (auto b : A()) {
+ __range.begin(); // expected-error {{use of undeclared identifier '__range'}}
+ ++__begin; // expected-error {{use of undeclared identifier '__begin'}}
+ --__end; // expected-error {{use of undeclared identifier '__end'}}
+ }
+
+ for (char c : "test")
+ ;
+ for (auto a : f()) // expected-error {{cannot use type 'void' as a range}}
+ ;
+
+ extern int incomplete[];
+ for (auto a : incomplete) // expected-error {{cannot use incomplete type 'int []' as a range}}
+ ;
+ extern struct Incomplete also_incomplete[2]; // expected-note {{forward declaration}}
+ for (auto &a : also_incomplete) // expected-error {{cannot use incomplete type 'struct Incomplete [2]' as a range}}
+ ;
+
+ struct VoidBegin {
+ void begin(); // expected-note {{selected 'begin' function with iterator type 'void'}}
+ void end();
+ };
+ for (auto a : VoidBegin()) // expected-error {{cannot use type 'void' as an iterator}}
+ ;
+
+ struct null_t {
+ operator int*();
+ };
+ struct Differ {
+ int *begin(); // expected-note {{selected 'begin' function with iterator type 'int *'}}
+ null_t end(); // expected-note {{selected 'end' function with iterator type 'null_t'}}
+ };
+ for (auto a : Differ()) // expected-error {{'begin' and 'end' must return the same type (got 'int *' and 'null_t')}}
+ ;
+
+ for (void f() : "error") // expected-error {{for range declaration must declare a variable}}
+ ;
+
+ for (extern int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'extern'}}
+ for (static int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'static'}}
+ for (register int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'register'}}
+ for (constexpr int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'constexpr'}}
+
+ struct NoBeginADL {
+ null_t alt_end();
+ };
+ struct NoEndADL {
+ null_t alt_begin();
+ };
+ for (auto u : NoBeginADL()) { // expected-error {{no matching function for call to 'begin'}} expected-note {{range has type 'NoBeginADL'}}
+ }
+ for (auto u : NoEndADL()) { // expected-error {{no matching function for call to 'end'}} expected-note {{range has type 'NoEndADL'}}
+ }
+
+ struct NoBegin {
+ null_t end();
+ };
+ struct NoEnd {
+ null_t begin();
+ };
+ for (auto u : NoBegin()) { // expected-error {{range type 'NoBegin' has 'end' member but no 'begin' member}}
+ }
+ for (auto u : NoEnd()) { // expected-error {{range type 'NoEnd' has 'begin' member but no 'end' member}}
+ }
+
+ struct NoIncr {
+ void *begin(); // expected-note {{selected 'begin' function with iterator type 'void *'}}
+ void *end();
+ };
+ for (auto u : NoIncr()) { // expected-error {{arithmetic on a pointer to void}}
+ }
+
+ struct NoNotEq {
+ NoNotEq begin(); // expected-note {{selected 'begin' function with iterator type 'NoNotEq'}}
+ NoNotEq end();
+ void operator++();
+ };
+ for (auto u : NoNotEq()) { // expected-error {{invalid operands to binary expression}}
+ }
+
+ struct NoCopy {
+ NoCopy();
+ NoCopy(const NoCopy &) = delete;
+ int *begin();
+ int *end();
+ };
+ for (int n : NoCopy()) { // ok
+ }
+
+ for (int n : 42) { // expected-error {{no matching function for call to 'begin'}} \
+ expected-note {{range has type 'int'}}
+ }
+
+ for (auto a : *also_incomplete) { // expected-error {{cannot use incomplete type 'struct Incomplete' as a range}}
+ }
+}
+
+template<typename T, typename U>
+void h(T t) {
+ for (U u : t) { // expected-error {{no viable conversion from 'A' to 'int'}}
+ }
+ for (auto u : t) {
+ }
+}
+
+template void h<A, int>(A);
+template void h<A(&)[4], A &>(A(&)[4]);
+template void h<A(&)[13], A>(A(&)[13]);
+template void h<A(&)[13], int>(A(&)[13]); // expected-note {{requested here}}
+
+template<typename T>
+void i(T t) {
+ for (auto u : t) { // expected-error {{no matching function for call to 'begin'}} \
+ expected-error {{member function 'begin' not viable}} \
+ expected-note {{range has type}}
+ }
+}
+template void i<A[13]>(A*); // expected-note {{requested here}}
+template void i<const A>(const A); // expected-note {{requested here}}
+
+namespace NS {
+ class ADL {};
+ int *begin(ADL); // expected-note {{no known conversion from 'NS::NoADL' to 'NS::ADL'}}
+ int *end(ADL);
+
+ class NoADL {};
+}
+int *begin(NS::NoADL);
+int *end(NS::NoADL);
+
+struct VoidBeginADL {};
+void begin(VoidBeginADL); // expected-note {{selected 'begin' function with iterator type 'void'}}
+void end(VoidBeginADL);
+
+void j() {
+ for (auto u : NS::ADL()) {
+ }
+ for (auto u : NS::NoADL()) { // expected-error {{no matching function for call to 'begin'}} expected-note {{range has type}}
+ }
+ for (auto a : VoidBeginADL()) { // expected-error {{cannot use type 'void' as an iterator}}
+ }
+}
+
+void example() {
+ int array[5] = { 1, 2, 3, 4, 5 };
+ for (int &x : array)
+ x *= 2;
+}
diff --git a/clang/test/CXX/stmt.stmt/stmt.label/p1.cpp b/clang/test/CXX/stmt.stmt/stmt.label/p1.cpp
new file mode 100644
index 0000000..90367f8
--- /dev/null
+++ b/clang/test/CXX/stmt.stmt/stmt.label/p1.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void f()
+{
+ int x = 0;
+ goto label1;
+
+label1: // expected-note{{previous definition is here}}
+ x = 1;
+ goto label2; // expected-error{{use of undeclared label 'label2'}}
+
+label1: // expected-error{{redefinition of label 'label1'}}
+ x = 2;
+}
+
+void h()
+{
+ int x = 0;
+ switch (x)
+ {
+ case 1:;
+ default:; // expected-error{{multiple default labels in one switch}}
+ default:; // expected-note{{previous case defined here}}
+ }
+}
diff --git a/clang/test/CXX/stmt.stmt/stmt.select/p3.cpp b/clang/test/CXX/stmt.stmt/stmt.select/p3.cpp
new file mode 100644
index 0000000..35e5c91
--- /dev/null
+++ b/clang/test/CXX/stmt.stmt/stmt.select/p3.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int f();
+
+void g() {
+ if (int x = f()) { // expected-note 2{{previous definition}}
+ int x; // expected-error{{redefinition of 'x'}}
+ } else {
+ int x; // expected-error{{redefinition of 'x'}}
+ }
+}
+
+
+void h() {
+ if (int x = f()) // expected-note 2{{previous definition}}
+ int x; // expected-error{{redefinition of 'x'}}
+ else
+ int x; // expected-error{{redefinition of 'x'}}
+}
diff --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p2-0x.cpp b/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p2-0x.cpp
new file mode 100644
index 0000000..000c870
--- /dev/null
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p2-0x.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -std=c++11 %s -verify
+
+struct Value {
+ constexpr Value(int n) : n(n) {}
+ constexpr operator short() { return n; }
+ int n;
+};
+enum E { E0, E1 };
+struct Alt {
+ constexpr operator E() { return E0; }
+};
+
+constexpr short s = Alt();
+
+void test(Value v) {
+ switch (v) {
+ case Alt():
+ case E1:
+ case Value(2):
+ case 3:
+ break;
+ }
+ switch (Alt a = Alt()) {
+ case Alt():
+ case E1:
+ case Value(2):
+ case 3:
+ break;
+ }
+ switch (E0) {
+ case Alt():
+ case E1:
+ // FIXME: These should produce a warning that 2 and 3 are not values of the
+ // enumeration.
+ case Value(2):
+ case 3:
+ break;
+ }
+}