summaryrefslogtreecommitdiffstats
path: root/clang/test/CXX
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/CXX')
-rw-r--r--clang/test/CXX/drs/dr16xx.cpp94
-rw-r--r--clang/test/CXX/drs/dr18xx.cpp11
-rw-r--r--clang/test/CXX/special/class.copy/p11.0x.copy.cpp13
-rw-r--r--clang/test/CXX/special/class.copy/p11.0x.move.cpp2
-rw-r--r--clang/test/CXX/special/class.ctor/p5-0x.cpp6
-rw-r--r--clang/test/CXX/temp/temp.param/p5.cpp12
6 files changed, 128 insertions, 10 deletions
diff --git a/clang/test/CXX/drs/dr16xx.cpp b/clang/test/CXX/drs/dr16xx.cpp
index e0af95ac39e..54648cfe969 100644
--- a/clang/test/CXX/drs/dr16xx.cpp
+++ b/clang/test/CXX/drs/dr16xx.cpp
@@ -9,6 +9,20 @@
#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
#endif
+#if __cplusplus >= 201103L
+namespace std {
+ typedef decltype(sizeof(int)) size_t;
+
+ template<typename E> class initializer_list {
+ const E *begin;
+ size_t size;
+
+ public:
+ initializer_list();
+ };
+} // std
+#endif
+
namespace dr1611 { // dr1611: dup 1658
struct A { A(int); };
struct B : virtual A { virtual void f() = 0; };
@@ -269,3 +283,83 @@ namespace dr1687 { // dr1687: 7
auto c = To<E1>() <=> To<E2>(); // expected-error {{invalid operands to binary expression ('To<dr1687::E1>' and 'To<dr1687::E2>')}}
#endif
}
+
+namespace dr1696 { // dr1696: 7
+ namespace std_examples {
+#if __cplusplus >= 201402L
+ extern struct A a;
+ struct A {
+ const A &x = { A{a, a} };
+ const A &y = { A{} }; // expected-error {{default member initializer for 'y' needed within definition of enclosing class 'A' outside of member functions}} expected-note {{here}}
+ };
+ A a{a, a};
+#endif
+ }
+
+ struct A { A(); ~A(); };
+#if __cplusplus >= 201103L
+ struct B {
+ A &&a; // expected-note {{declared here}}
+ B() : a{} {} // expected-error {{reference member 'a' binds to a temporary object whose lifetime would be shorter than the constructed object}}
+ } b;
+#endif
+
+ struct C {
+ C();
+ const A &a; // expected-note {{declared here}}
+ };
+ C::C() : a(A()) {} // expected-error {{reference member 'a' binds to a temporary object whose lifetime would be shorter than the constructed object}}
+
+#if __cplusplus >= 201103L
+ // This is OK in C++14 onwards, per DR1815, though we don't support that yet:
+ // D1 d1 = {};
+ // is equivalent to
+ // D1 d1 = {A()};
+ // ... which lifetime-extends the A temporary.
+ struct D1 {
+ const A &a = A();
+#if __cplusplus < 201402L
+ // expected-error@-2 {{binds to a temporary}}
+ // expected-note@-4 {{here}}
+#else
+ // expected-warning-re@-5 {{sorry, lifetime extension {{.*}} not supported}}
+#endif
+ };
+ D1 d1 = {}; // expected-note {{here}}
+
+ struct D2 {
+ const A &a = A(); // expected-error {{binds to a temporary}}
+ D2() {} // expected-note {{used here}}
+ };
+
+ struct D3 { // expected-note {{used here}}
+ const A &a = A(); // expected-error {{binds to a temporary}}
+ };
+ D3 d3; // expected-note {{first required here}}
+
+ struct haslist1 {
+ std::initializer_list<int> il; // expected-note {{'std::initializer_list' member}}
+ haslist1(int i) : il{i, 2, 3} {} // expected-error {{backing array for 'std::initializer_list' member 'il' is a temporary object}}
+ };
+
+ struct haslist2 {
+ std::initializer_list<int> il; // expected-note {{'std::initializer_list' member}}
+ haslist2();
+ };
+ haslist2::haslist2() : il{1, 2} {} // expected-error {{backing array for 'std::initializer_list' member 'il' is a temporary object}}
+
+ struct haslist3 {
+ std::initializer_list<int> il = {1, 2, 3};
+ };
+
+ struct haslist4 { // expected-note {{in default member initializer}}
+ std::initializer_list<int> il = {1, 2, 3}; // expected-error {{backing array for 'std::initializer_list' member 'il' is a temporary object}}
+ };
+ haslist4 hl4; // expected-note {{in implicit default constructor}}
+
+ struct haslist5 {
+ std::initializer_list<int> il = {1, 2, 3}; // expected-error {{backing array for 'std::initializer_list' member 'il' is a temporary object}}
+ haslist5() {} // expected-note {{in default member initializer}}
+ };
+#endif
+}
diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index a0f470ed4a2..f6a4676bc7b 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -30,6 +30,17 @@ namespace dr1813 { // dr1813: 7
static_assert(!__is_standard_layout(U), "");
}
+namespace dr1815 { // dr1815: no
+#if __cplusplus >= 201402L
+ // FIXME: needs codegen test
+ struct A { int &&r = 0; }; // FIXME expected-warning {{not supported}}
+ A a = {}; // expected-note {{here}}
+
+ struct B { int &&r = 0; }; // expected-error {{binds to a temporary}} expected-note {{here}}
+ B b; // expected-note {{here}}
+#endif
+}
+
namespace dr1881 { // dr1881: 7
struct A { int a : 4; };
struct B : A { int b : 3; };
diff --git a/clang/test/CXX/special/class.copy/p11.0x.copy.cpp b/clang/test/CXX/special/class.copy/p11.0x.copy.cpp
index 1ca0143d093..a4d0cdcdc73 100644
--- a/clang/test/CXX/special/class.copy/p11.0x.copy.cpp
+++ b/clang/test/CXX/special/class.copy/p11.0x.copy.cpp
@@ -121,13 +121,22 @@ extern HasNoAccessDtorBase HNADBa;
HasNoAccessDtorBase HNADBb(HNADBa); // expected-error{{implicitly-deleted copy constructor}}
// -- a non-static data member of rvalue reference type
+int some_int;
struct RValue {
- int && ri = 1; // expected-note{{copy constructor of 'RValue' is implicitly deleted because field 'ri' is of rvalue reference type 'int &&'}}
- // expected-warning@-1{{binding reference member 'ri' to a temporary}} expected-note@-1 {{here}}
+ int && ri = static_cast<int&&>(some_int); // expected-note{{copy constructor of 'RValue' is implicitly deleted because field 'ri' is of rvalue reference type 'int &&'}}
};
RValue RVa;
RValue RVb(RVa); // expected-error{{call to implicitly-deleted copy constructor}}
+// FIXME: The note on the class-name is attached to the location of the
+// constructor. This is not especially clear.
+struct RValueTmp { // expected-note {{used here}}
+ int && ri = 1; // expected-note{{copy constructor of 'RValueTmp' is implicitly deleted because field 'ri' is of rvalue reference type 'int &&'}}
+ // expected-error@-1 {{reference member 'ri' binds to a temporary}}
+};
+RValueTmp RVTa; // expected-note {{implicit default constructor for 'RValueTmp' first required here}}
+RValueTmp RVTb(RVTa); // expected-error{{call to implicitly-deleted copy constructor}}
+
namespace PR13381 {
struct S {
S(const S&);
diff --git a/clang/test/CXX/special/class.copy/p11.0x.move.cpp b/clang/test/CXX/special/class.copy/p11.0x.move.cpp
index ab4259548e7..5b016836e9e 100644
--- a/clang/test/CXX/special/class.copy/p11.0x.move.cpp
+++ b/clang/test/CXX/special/class.copy/p11.0x.move.cpp
@@ -145,7 +145,7 @@ HasNoAccessDtorBase HNADBb(HNADBa); // expected-error{{implicitly-deleted copy c
// The restriction on rvalue reference members applies to only the copy
// constructor.
struct RValue {
- int &&ri = 1; // expected-warning {{binding reference member 'ri' to a temporary}} expected-note {{here}}
+ int &&ri = 1;
RValue(RValue&&);
};
RValue::RValue(RValue&&) = default;
diff --git a/clang/test/CXX/special/class.ctor/p5-0x.cpp b/clang/test/CXX/special/class.ctor/p5-0x.cpp
index 2360345a484..5558313ce78 100644
--- a/clang/test/CXX/special/class.ctor/p5-0x.cpp
+++ b/clang/test/CXX/special/class.ctor/p5-0x.cpp
@@ -43,8 +43,12 @@ class NotDeleted2a { int &a = n; };
NotDeleted2a nd2a;
class NotDeleted2b { int &a = error; }; // expected-error {{undeclared identifier}}
NotDeleted2b nd2b;
-class NotDeleted2c { int &&a = 0; }; // expected-warning {{binding reference member 'a' to a temporary}} expected-note {{here}}
+class NotDeleted2c { int &&a = static_cast<int&&>(n); };
NotDeleted2c nd2c;
+// Note: this one does not have a deleted default constructor even though the
+// implicit default constructor is ill-formed!
+class NotDeleted2d { int &&a = 0; }; // expected-error {{reference member 'a' binds to a temporary object}} expected-note {{here}}
+NotDeleted2d nd2d; // expected-note {{first required here}}
// - any non-variant non-static data member of const qualified type (or array
// thereof) with no brace-or-equal-initializer does not have a user-provided
diff --git a/clang/test/CXX/temp/temp.param/p5.cpp b/clang/test/CXX/temp/temp.param/p5.cpp
index aa0d7e92b9e..de902a5e4d0 100644
--- a/clang/test/CXX/temp/temp.param/p5.cpp
+++ b/clang/test/CXX/temp/temp.param/p5.cpp
@@ -1,13 +1,13 @@
// RUN: %clang_cc1 -verify %s -std=c++14
-template<const int I> struct S {
+template<const int I> struct S { // expected-note {{in default member initializer}}
decltype(I) n;
- int &&r = I; // expected-warning 2{{binding reference member 'r' to a temporary value}} expected-note 2{{declared here}}
+ int &&r = I; // expected-error {{reference member 'r' binds to a temporary object}}
};
-S<5> s; // expected-note {{instantiation}}
+S<5> s; // expected-note {{implicit default constructor}}
-template<typename T, T v> struct U {
+template<typename T, T v> struct U { // expected-note {{in default member initializer}}
decltype(v) n;
- int &&r = v; // expected-warning {{binding reference member 'r' to a temporary value}} expected-note {{declared here}}
+ int &&r = v; // expected-error {{reference member 'r' binds to a temporary object}}
};
-U<const int, 6> u; // expected-note {{instantiation}}
+U<const int, 6> u; // expected-note {{implicit default constructor}}
OpenPOWER on IntegriCloud