summaryrefslogtreecommitdiffstats
path: root/test/CXX/dcl.decl/dcl.init
diff options
context:
space:
mode:
Diffstat (limited to 'test/CXX/dcl.decl/dcl.init')
-rw-r--r--test/CXX/dcl.decl/dcl.init/dcl.init.list/p3-0x.cpp33
-rw-r--r--test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp8
-rw-r--r--test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-examples.cpp14
-rw-r--r--test/CXX/dcl.decl/dcl.init/p5.cpp48
4 files changed, 74 insertions, 29 deletions
diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3-0x.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3-0x.cpp
index 3450003..d61f6e3 100644
--- a/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3-0x.cpp
+++ b/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3-0x.cpp
@@ -21,7 +21,7 @@ namespace std {
};
}
-namespace bullet2 {
+namespace bullet1 {
double ad[] = { 1, 2.0 };
int ai[] = { 1, 2.0 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
@@ -62,12 +62,16 @@ namespace bullet4_example3 {
};
S s1 = { 1, 2, 3.0 };
- // FIXME: This is an ill-formed narrowing initialization.
- S s2 { 1.0, 2, 3 };
+ S s2 { 1.0, 2, 3 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
S s3 {};
}
namespace bullet5 {
+ int x1 {2};
+ int x2 {2.0}; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
+}
+
+namespace bullet6 {
struct S {
S(std::initializer_list<double>) {}
S(const std::string &) {}
@@ -75,17 +79,12 @@ namespace bullet5 {
const S& r1 = { 1, 2, 3.0 };
const S& r2 = { "Spinach" };
- S& r3 = { 1, 2, 3 }; // expected-error {{non-const lvalue reference to type 'bullet5::S' cannot bind to an initializer list temporary}}
+ S& r3 = { 1, 2, 3 }; // expected-error {{non-const lvalue reference to type 'bullet6::S' cannot bind to an initializer list temporary}}
const int& i1 = { 1 };
const int& i2 = { 1.1 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}} expected-warning {{implicit conversion}}
const int (&iar)[2] = { 1, 2 };
}
-namespace bullet6 {
- int x1 {2};
- int x2 {2.0}; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
-}
-
namespace bullet7 {
int** pp {};
}
@@ -99,15 +98,25 @@ namespace bullet8 {
B(std::initializer_list<int> i) {}
};
B b1 { 1, 2 };
- B b2 { 1, 2.0 };
+ B b2 { 1, 2.0 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
struct C {
C(int i, double j) {}
};
C c1 = { 1, 2.2 };
- // FIXME: This is an ill-formed narrowing initialization.
- C c2 = { 1.1, 2 }; // expected-warning {{implicit conversion}}
+ // FIXME: Suppress the narrowing warning in the cases where we issue a narrowing error.
+ C c2 = { 1.1, 2 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}} expected-warning {{implicit conversion}}
int j { 1 };
int k { };
}
+
+namespace rdar13395022 {
+ struct MoveOnly {
+ MoveOnly(MoveOnly&&); // expected-note{{copy constructor is implicitly deleted because 'MoveOnly' has a user-declared move constructor}}
+ };
+
+ void test(MoveOnly mo) {
+ auto &&list = {mo}; // expected-error{{call to implicitly-deleted copy constructor of 'rdar13395022::MoveOnly'}}
+ }
+}
diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp
index adbdff6..812d0de 100644
--- a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp
+++ b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp
@@ -192,3 +192,11 @@ namespace PR11003 {
Value y(Move(0));
}
}
+
+namespace rdar13278115 {
+ struct X { };
+ struct Y : X { };
+ X &&f0(X &x) { return x; } // expected-error{{rvalue reference to type 'rdar13278115::X' cannot bind to lvalue of type 'rdar13278115::X'}}
+ X &&f1(Y &y) { return y; } // expected-error{{rvalue reference to type 'rdar13278115::X' cannot bind to lvalue of type 'rdar13278115::Y'}}
+ const X &&f2(Y &y) { return y; } // expected-error{{rvalue reference to type 'const rdar13278115::X' cannot bind to lvalue of type 'rdar13278115::Y'}}
+}
diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-examples.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-examples.cpp
index 08d9639..be1113d 100644
--- a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-examples.cpp
+++ b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-examples.cpp
@@ -3,10 +3,10 @@
// CHECK: example0
void example0() {
double d = 2.0;
- // CHECK: double &rd =
+ // CHECK: VarDecl{{.*}}rd 'double &'
// CHECK-NEXT: DeclRefExpr
double &rd = d;
- // CHECK: const double &rcd =
+ // CHECK: VarDecl{{.*}}rcd 'const double &'
// CHECK-NEXT: ImplicitCastExpr{{.*}}'const double' lvalue <NoOp>
const double &rcd = d;
}
@@ -16,10 +16,10 @@ struct B : A { } b;
// CHECK: example1
void example1() {
- // CHECK: A &ra =
+ // CHECK: VarDecl{{.*}}ra 'struct A &'
// CHECK: ImplicitCastExpr{{.*}}'struct A' lvalue <DerivedToBase (A)>
A &ra = b;
- // CHECK: const A &rca =
+ // CHECK: VarDecl{{.*}}rca 'const struct A &'
// CHECK: ImplicitCastExpr{{.*}}'const struct A' lvalue <NoOp>
// CHECK: ImplicitCastExpr{{.*}}'struct A' lvalue <DerivedToBase (A)>
const A& rca = b;
@@ -33,12 +33,12 @@ struct X {
// CHECK: example2
void example2() {
- // CHECK: const A &rca =
+ // CHECK: VarDecl{{.*}}rca 'const struct A &'
// CHECK: ImplicitCastExpr{{.*}}'const struct A' <NoOp>
// CHECK: ImplicitCastExpr{{.*}}'struct A' <DerivedToBase (A)>
// CHECK: CallExpr{{.*}}B
const A &rca = f();
- // CHECK: const A &r =
+ // CHECK: VarDecl{{.*}}r 'const struct A &'
// CHECK: ImplicitCastExpr{{.*}}'const struct A' <NoOp>
// CHECK: ImplicitCastExpr{{.*}}'struct A' <DerivedToBase (A)>
// CHECK: CXXMemberCallExpr{{.*}}'struct B'
@@ -47,7 +47,7 @@ void example2() {
// CHECK: example3
void example3() {
- // CHECK: const double &rcd2 =
+ // CHECK: VarDecl{{.*}}rcd2 'const double &'
// CHECK: ImplicitCastExpr{{.*}} <IntegralToFloating>
const double& rcd2 = 2;
}
diff --git a/test/CXX/dcl.decl/dcl.init/p5.cpp b/test/CXX/dcl.decl/dcl.init/p5.cpp
index b50e8d7..e7ccb2e 100644
--- a/test/CXX/dcl.decl/dcl.init/p5.cpp
+++ b/test/CXX/dcl.decl/dcl.init/p5.cpp
@@ -1,20 +1,48 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-// FIXME: Very incomplete!
-
// A program that calls for default-initialization or value-initialization of
// an entity of reference type is illformed. If T is a cv-qualified type, the
// cv-unqualified version of T is used for these definitions of
// zero-initialization, default-initialization, and value-initialization.
-//
-// FIXME: The diagnostics for these errors are terrible because they fall out
-// of the AST representation rather than being explicitly issued during the
-// respective initialization forms.
-struct S { // expected-error {{implicit default constructor for 'S' must explicitly initialize the reference member}} \
- // expected-note {{candidate constructor (the implicit copy constructor) not viable}}
- int& x; // expected-note {{declared here}}
+
+struct S { // expected-error {{implicit default constructor for 'S' must explicitly initialize the reference member}}
+ int &x; // expected-note {{declared here}} expected-error 3{{reference to type 'int' requires an initializer}}
};
S s; // expected-note {{implicit default constructor for 'S' first required here}}
S f() {
- return S(); // expected-error {{no matching constructor for initialization of 'S'}}
+ return S(); // expected-note {{in value-initialization of type 'S' here}}
}
+
+struct T
+ : S { // expected-note 2{{in value-initialization of type 'S' here}}
+};
+T t = T(); // expected-note {{in value-initialization of type 'T' here}}
+
+struct U {
+ T t[3]; // expected-note {{in value-initialization of type 'T' here}}
+};
+U u = U(); // expected-note {{in value-initialization of type 'U' here}}
+
+// Ensure that we handle C++11 in-class initializers properly as an extension.
+// In this case, there is no user-declared default constructor, so we
+// recursively apply the value-initialization checks, but we will emit a
+// constructor call anyway, because the default constructor is not trivial.
+struct V {
+ int n;
+ int &r = n; // expected-warning {{C++11}}
+};
+V v = V(); // ok
+struct W {
+ int n;
+ S s = { n }; // expected-warning {{C++11}}
+};
+W w = W(); // ok
+
+// Ensure we're not faking this up by making the default constructor
+// non-trivial.
+#define static_assert(B, S) typedef int assert_failed[(B) ? 1 : -1];
+static_assert(__has_trivial_constructor(S), "");
+static_assert(__has_trivial_constructor(T), "");
+static_assert(__has_trivial_constructor(U), "");
+static_assert(!__has_trivial_constructor(V), "");
+static_assert(!__has_trivial_constructor(W), "");
OpenPOWER on IntegriCloud