aboutsummaryrefslogtreecommitdiff
path: root/test/CXX/dcl.decl
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2012-08-15 20:02:54 +0000
committerDimitry Andric <dim@FreeBSD.org>2012-08-15 20:02:54 +0000
commit56d91b49b13fe55c918afbda19f6165b5fbff87a (patch)
tree9abb1a658a297776086f4e0dfa6ca533de02104e /test/CXX/dcl.decl
parent41e20f564abdb05101d6b2b29c59459a966c22cc (diff)
downloadsrc-56d91b49b13fe55c918afbda19f6165b5fbff87a.tar.gz
src-56d91b49b13fe55c918afbda19f6165b5fbff87a.zip
Vendor import of clang trunk r161861:vendor/clang/clang-trunk-r161861
Notes
Notes: svn path=/vendor/clang/dist/; revision=239313 svn path=/vendor/clang/clang-trunk-r161861/; revision=239314; tag=vendor/clang/clang-trunk-r161861
Diffstat (limited to 'test/CXX/dcl.decl')
-rw-r--r--test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp76
-rw-r--r--test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.delete/p4.cpp8
-rw-r--r--test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp2
-rw-r--r--test/CXX/dcl.decl/dcl.init/dcl.init.list/p3-0x.cpp113
-rw-r--r--test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp14
-rw-r--r--test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp2
-rw-r--r--test/CXX/dcl.decl/dcl.meaning/dcl.fct/dcl.fct.def.default/p1.cpp16
-rw-r--r--test/CXX/dcl.decl/dcl.meaning/dcl.fct/dcl.fct.def.default/p2.cpp27
-rw-r--r--test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp6
9 files changed, 250 insertions, 14 deletions
diff --git a/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp b/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
index 06dd1bb05560..783aba182319 100644
--- a/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
+++ b/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -fcxx-exceptions %s
// An explicitly-defaulted function may be declared constexpr only if it would
// have been implicitly declared as constexpr.
@@ -27,7 +27,7 @@ struct S2 {
// -- it is implicitly considered to be constexpr if the implicit declaration
// would be
struct S3 {
- S3() = default; // expected-note {{here}}
+ S3() = default;
S3(const S3&) = default;
S3(S3&&) = default;
constexpr S3(int n) : n(n) {}
@@ -36,7 +36,7 @@ struct S3 {
constexpr S3 s3a = S3(0);
constexpr S3 s3b = s3a;
constexpr S3 s3c = S3();
-constexpr S3 s3d; // expected-error {{constant expression}} expected-note {{non-constexpr constructor}}
+constexpr S3 s3d; // expected-error {{default initialization of an object of const type 'const S3' requires a user-provided default constructor}}
struct S4 {
S4() = default;
@@ -44,7 +44,7 @@ struct S4 {
S4(S4&&) = default; // expected-note {{here}}
NoCopyMove ncm;
};
-constexpr S4 s4a; // ok
+constexpr S4 s4a{}; // ok
constexpr S4 s4b = S4(); // expected-error {{constant expression}} expected-note {{non-constexpr constructor}}
constexpr S4 s4c = s4a; // expected-error {{constant expression}} expected-note {{non-constexpr constructor}}
@@ -54,3 +54,71 @@ struct S5 {
};
constexpr S5::S5() = default;
static_assert(S5().m == 4, "");
+
+
+// An explicitly-defaulted function may have an exception specification only if
+// it is compatible with the exception specification on an implicit declaration.
+struct E1 {
+ E1() noexcept = default;
+ E1(const E1&) noexcept = default;
+ E1(E1&&) noexcept = default;
+ E1 &operator=(const E1&) noexcept = default;
+ E1 &operator=(E1&&) noexcept = default;
+ ~E1() noexcept = default;
+};
+struct E2 {
+ E2() noexcept(false) = default; // expected-error {{exception specification of explicitly defaulted default constructor does not match the calculated one}}
+ E2(const E2&) noexcept(false) = default; // expected-error {{exception specification of explicitly defaulted copy constructor does not match the calculated one}}
+ E2(E2&&) noexcept(false) = default; // expected-error {{exception specification of explicitly defaulted move constructor does not match the calculated one}}
+ E2 &operator=(const E2&) noexcept(false) = default; // expected-error {{exception specification of explicitly defaulted copy assignment operator does not match the calculated one}}
+ E2 &operator=(E2&&) noexcept(false) = default; // expected-error {{exception specification of explicitly defaulted move assignment operator does not match the calculated one}}
+ ~E2() noexcept(false) = default; // expected-error {{exception specification of explicitly defaulted destructor does not match the calculated one}}
+};
+
+// If a function is explicitly defaulted on its first declaration
+// -- it is implicitly considered to have the same exception-specification as
+// if it had been implicitly declared
+struct E3 {
+ E3() = default;
+ E3(const E3&) = default;
+ E3(E3&&) = default;
+ E3 &operator=(const E3&) = default;
+ E3 &operator=(E3&&) = default;
+ ~E3() = default;
+};
+E3 e3;
+static_assert(noexcept(E3(), E3(E3()), E3(e3), e3 = E3(), e3 = e3), "");
+struct E4 {
+ E4() noexcept(false);
+ E4(const E4&) noexcept(false);
+ E4(E4&&) noexcept(false);
+ E4 &operator=(const E4&) noexcept(false);
+ E4 &operator=(E4&&) noexcept(false);
+ ~E4() noexcept(false);
+};
+struct E5 {
+ E5() = default;
+ E5(const E5&) = default;
+ E5(E5&&) = default;
+ E5 &operator=(const E5&) = default;
+ E5 &operator=(E5&&) = default;
+ ~E5() = default;
+
+ E4 e4;
+};
+E5 e5;
+static_assert(!noexcept(E5()), "");
+static_assert(!noexcept(E5(static_cast<E5&&>(e5))), "");
+static_assert(!noexcept(E5(e5)), "");
+static_assert(!noexcept(e5 = E5()), "");
+static_assert(!noexcept(e5 = e5), "");
+
+namespace PR13492 {
+ struct B {
+ B() = default;
+ };
+
+ void f() {
+ const B b; // expected-error {{default initialization of an object of const type 'const PR13492::B' requires a user-provided default constructor}}
+ }
+}
diff --git a/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.delete/p4.cpp b/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.delete/p4.cpp
new file mode 100644
index 000000000000..16fd5e6dbda1
--- /dev/null
+++ b/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.delete/p4.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+template<typename> void func();
+template<> void func<int>() = delete;
+
+template<typename> void func2();
+template<> void func2<int>(); // expected-note {{previous declaration is here}}
+template<> void func2<int>() = delete; // expected-error {{deleted definition must be first declaration}}
diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp
index 7764980e34f7..fef3692609fa 100644
--- a/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp
+++ b/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp
@@ -72,7 +72,7 @@ struct DefaultedAggr {
DefaultedAggr(const DefaultedAggr &) = default;
DefaultedAggr(DefaultedAggr &&) = default;
DefaultedAggr &operator=(const DefaultedAggr &) = default;
- DefaultedAggr &operator=(DefaultedAggr &) = default;
+ DefaultedAggr &operator=(DefaultedAggr &&) = default;
~DefaultedAggr() = default;
};
DefaultedAggr da = { 42 } ;
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
new file mode 100644
index 000000000000..3450003a6e2d
--- /dev/null
+++ b/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3-0x.cpp
@@ -0,0 +1,113 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+namespace std {
+ typedef decltype(sizeof(int)) size_t;
+
+ template <typename E>
+ struct initializer_list
+ {
+ const E *p;
+ size_t n;
+ initializer_list(const E *p, size_t n) : p(p), n(n) {}
+ };
+
+ struct string {
+ string(const char *);
+ };
+
+ template<typename A, typename B>
+ struct pair {
+ pair(const A&, const B&);
+ };
+}
+
+namespace bullet2 {
+ 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}}
+
+ struct S2 {
+ int m1;
+ double m2, m3;
+ };
+
+ S2 s21 = { 1, 2, 3.0 };
+ S2 s22 { 1.0, 2, 3 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}}
+ S2 s23 { };
+}
+
+namespace bullet4_example1 {
+ struct S {
+ S(std::initializer_list<double> d) {}
+ S(std::initializer_list<int> i) {}
+ S() {}
+ };
+
+ S s1 = { 1.0, 2.0, 3.0 };
+ S s2 = { 1, 2, 3 };
+ S s3 = { };
+}
+
+namespace bullet4_example2 {
+ struct Map {
+ Map(std::initializer_list<std::pair<std::string,int>>) {}
+ };
+
+ Map ship = {{"Sophie",14}, {"Surprise",28}};
+}
+
+namespace bullet4_example3 {
+ struct S {
+ S(int, double, double) {}
+ S() {}
+ };
+
+ S s1 = { 1, 2, 3.0 };
+ // FIXME: This is an ill-formed narrowing initialization.
+ S s2 { 1.0, 2, 3 };
+ S s3 {};
+}
+
+namespace bullet5 {
+ struct S {
+ S(std::initializer_list<double>) {}
+ S(const std::string &) {}
+ };
+
+ 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}}
+ 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 {};
+}
+
+namespace bullet8 {
+ struct A { int i; int j; };
+ A a1 { 1, 2 };
+ A a2 { 1.2 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{override}} expected-warning {{implicit conversion}}
+
+ struct B {
+ B(std::initializer_list<int> i) {}
+ };
+ B b1 { 1, 2 };
+ B b2 { 1, 2.0 };
+
+ 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}}
+
+ int j { 1 };
+ int k { };
+}
diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
index db20ea6426e0..9b1727fd04af 100644
--- a/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
+++ b/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
@@ -167,6 +167,20 @@ void shrink_int() {
Agg<short> ce1 = { Convert<int>(100000) }; // expected-error {{constant expression evaluates to 100000 which cannot be narrowed to type 'short'}} expected-note {{override}} expected-warning {{changes value from 100000 to -31072}}
Agg<char> ce2 = { ConvertVar<short>() }; // expected-error {{non-constant-expression cannot be narrowed from type 'short' to 'char'}} expected-note {{override}}
+
+ // Negative -> larger unsigned type.
+ unsigned long long ll1 = { -1 }; // expected-error {{ -1 which cannot be narrowed}} expected-note {{override}}
+ unsigned long long ll2 = { 1 }; // OK
+ unsigned long long ll3 = { s }; // expected-error {{cannot be narrowed from type 'short'}} expected-note {{override}}
+ unsigned long long ll4 = { us }; // OK
+ unsigned long long ll5 = { ll }; // expected-error {{cannot be narrowed from type 'long long'}} expected-note {{override}}
+ Agg<unsigned long long> ll6 = { -1 }; // expected-error {{ -1 which cannot be narrowed}} expected-note {{override}}
+ Agg<unsigned long long> ll7 = { 18446744073709551615ULL }; // OK
+ Agg<unsigned long long> ll8 = { __int128(18446744073709551615ULL) + 1 }; // expected-error {{ 18446744073709551616 which cannot be narrowed}} expected-note {{override}} expected-warning {{changes value}}
+ signed char c = 'x';
+ unsigned short usc1 = { c }; // expected-error {{non-constant-expression cannot be narrowed from type 'signed char'}} expected-note {{override}}
+ unsigned short usc2 = { (signed char)'x' }; // OK
+ unsigned short usc3 = { (signed char)-1 }; // expected-error {{ -1 which cannot be narrowed}} expected-note {{override}}
}
// Be sure that type- and value-dependent expressions in templates get the error
diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp
index d58a12953e0d..4ba75efebbb3 100644
--- a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp
+++ b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp
@@ -22,7 +22,7 @@ struct X3 {
X3();
private:
- X3(X3&); // expected-note{{candidate constructor not viable: no known conversion from 'X3' to 'X3 &' for 1st argument}}
+ X3(X3&); // expected-note{{candidate constructor not viable: expects an l-value for 1st argument}}
};
// Check for instantiation of default arguments
diff --git a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/dcl.fct.def.default/p1.cpp b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/dcl.fct.def.default/p1.cpp
new file mode 100644
index 000000000000..21f71f05419c
--- /dev/null
+++ b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/dcl.fct.def.default/p1.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+
+// A function that is explicitly defaulted shall
+// [...]
+// -- not have default arguments
+struct DefArg {
+ static DefArg &&make();
+ DefArg(int n = 5) = default; // expected-error {{an explicitly-defaulted constructor cannot have default arguments}}
+ DefArg(const DefArg &DA = make()) = default; // expected-error {{an explicitly-defaulted constructor cannot have default arguments}}
+ DefArg(const DefArg &DA, int k = 3) = default; // expected-error {{an explicitly-defaulted copy constructor cannot have default arguments}}
+ DefArg(DefArg &&DA = make()) = default; // expected-error {{an explicitly-defaulted constructor cannot have default arguments}}
+ DefArg(DefArg &&DA, int k = 3) = default; // expected-error {{an explicitly-defaulted move constructor cannot have default arguments}}
+ DefArg &operator=(const DefArg&, int k = 4) = default; // expected-error {{parameter of overloaded 'operator=' cannot have a default argument}}
+ DefArg &operator=(DefArg&&, int k = 4) = default; // expected-error {{parameter of overloaded 'operator=' cannot have a default argument}}
+ ~DefArg(int k = 5) = default; // expected-error {{destructor cannot have any parameters}}
+};
diff --git a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/dcl.fct.def.default/p2.cpp b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/dcl.fct.def.default/p2.cpp
index a87982906631..9b5ef788974e 100644
--- a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/dcl.fct.def.default/p2.cpp
+++ b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/dcl.fct.def.default/p2.cpp
@@ -14,11 +14,11 @@ namespace move {
};
struct AssignmentRet1 {
- AssignmentRet1&& operator=(AssignmentRet1&&) = default; // expected-error {{an explicitly-defaulted move assignment operator must return an unqualified lvalue reference to its class type}}
+ AssignmentRet1&& operator=(AssignmentRet1&&) = default; // expected-error {{explicitly-defaulted move assignment operator must return 'move::AssignmentRet1 &'}}
};
struct AssignmentRet2 {
- const AssignmentRet2& operator=(AssignmentRet2&&) = default; // expected-error {{an explicitly-defaulted move assignment operator must return an unqualified lvalue reference to its class type}}
+ const AssignmentRet2& operator=(AssignmentRet2&&) = default; // expected-error {{explicitly-defaulted move assignment operator must return 'move::AssignmentRet2 &'}}
};
struct ConstAssignment {
@@ -38,22 +38,35 @@ namespace copy {
};
struct NonConst {
- NonConst(NonConst&) = default;
- NonConst& operator=(NonConst&) = default;
+ NonConst(NonConst&) = default; // expected-error {{must be defaulted outside the class}}
+ NonConst& operator=(NonConst&) = default; // expected-error {{must be defaulted outside the class}}
+ };
+
+ struct NonConst2 {
+ NonConst2(NonConst2&);
+ NonConst2& operator=(NonConst2&);
+ };
+ NonConst2::NonConst2(NonConst2&) = default;
+ NonConst2 &NonConst2::operator=(NonConst2&) = default;
+
+ struct NonConst3 {
+ NonConst3(NonConst3&) = default;
+ NonConst3& operator=(NonConst3&) = default;
+ NonConst nc;
};
struct BadConst {
- NonConst nc; // makes implicit copy non-const
BadConst(const BadConst&) = default; // expected-error {{is const, but}}
BadConst& operator=(const BadConst&) = default; // expected-error {{is const, but}}
+ NonConst nc; // makes implicit copy non-const
};
struct AssignmentRet1 {
- AssignmentRet1&& operator=(const AssignmentRet1&) = default; // expected-error {{an explicitly-defaulted copy assignment operator must return an unqualified lvalue reference to its class type}}
+ AssignmentRet1&& operator=(const AssignmentRet1&) = default; // expected-error {{explicitly-defaulted copy assignment operator must return 'copy::AssignmentRet1 &'}}
};
struct AssignmentRet2 {
- const AssignmentRet2& operator=(const AssignmentRet2&) = default; // expected-error {{an explicitly-defaulted copy assignment operator must return an unqualified lvalue reference to its class type}}
+ const AssignmentRet2& operator=(const AssignmentRet2&) = default; // expected-error {{explicitly-defaulted copy assignment operator must return 'copy::AssignmentRet2 &'}}
};
struct ConstAssignment {
diff --git a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
index 574a3e7a7934..719aeeddebcc 100644
--- a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
+++ b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
@@ -1,3 +1,7 @@
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
-auto j() -> enum { e3 }; // expected-error{{unnamed enumeration must be a definition}} expected-error {{requires a specifier or qualifier}} expected-error {{without trailing return type}}
+// FIXME: We should catch the case of tag with an incomplete type here (which
+// will necessarily be ill-formed as a trailing return type for a function
+// definition), and recover with a "type cannot be defined in a trailing return
+// type" error.
+auto j() -> enum { e3 }; // expected-error{{unnamed enumeration must be a definition}} expected-error {{expected a type}}