summaryrefslogtreecommitdiffstats
path: root/test/CXX/dcl.decl/dcl.init/p5.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/CXX/dcl.decl/dcl.init/p5.cpp')
-rw-r--r--test/CXX/dcl.decl/dcl.init/p5.cpp48
1 files changed, 38 insertions, 10 deletions
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