diff options
Diffstat (limited to 'test/CXX/dcl.decl')
-rw-r--r-- | test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp | 63 | ||||
-rw-r--r-- | test/CXX/dcl.decl/dcl.init/p14-0x.cpp | 44 | ||||
-rw-r--r-- | test/CXX/dcl.decl/dcl.init/p6.cpp | 12 |
3 files changed, 119 insertions, 0 deletions
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 new file mode 100644 index 0000000..9b92340 --- /dev/null +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp @@ -0,0 +1,63 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +// An aggregate is an array or a class... +struct Aggr { +private: + static const int n; + void f(); +protected: + struct Inner { int m; }; +public: + bool &br; +}; +bool b; +Aggr ag = { b }; + +// with no user-provided constructors, ... +struct NonAggr1a { + NonAggr1a(int, int); + int k; +}; +// In C++03, this is {{non-aggregate type 'NonAggr1a'}}. +// In C++0x, 'user-provided' is only defined for special member functions, so +// this type is considered to be an aggregate. This is probably a langauge +// defect. +NonAggr1a na1a = { 42 }; + +struct NonAggr1b { + NonAggr1b(const NonAggr1b &); + int k; +}; +NonAggr1b na1b = { 42 }; // expected-error {{non-aggregate type 'NonAggr1b'}} + +// no brace-or-equal-initializers for non-static data members, ... +struct NonAggr2 { + int m = { 123 }; +}; +NonAggr2 na2 = { 42 }; // expected-error {{non-aggregate type 'NonAggr2'}} + +// no private... +struct NonAggr3 { +private: + int n; +}; +NonAggr3 na3 = { 42 }; // expected-error {{non-aggregate type 'NonAggr3'}} + +// or protected non-static data members, ... +struct NonAggr4 { +protected: + int n; +}; +NonAggr4 na4 = { 42 }; // expected-error {{non-aggregate type 'NonAggr4'}} + +// no base classes, ... +struct NonAggr5 : Aggr { +}; +NonAggr5 na5 = { b }; // expected-error {{non-aggregate type 'NonAggr5'}} + +// and no virtual functions. +struct NonAggr6 { + virtual void f(); + int n; +}; +NonAggr6 na6 = { 42 }; // expected-error {{non-aggregate type 'NonAggr6'}} diff --git a/test/CXX/dcl.decl/dcl.init/p14-0x.cpp b/test/CXX/dcl.decl/dcl.init/p14-0x.cpp new file mode 100644 index 0000000..e5b5889 --- /dev/null +++ b/test/CXX/dcl.decl/dcl.init/p14-0x.cpp @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +struct NoDefault { + NoDefault() = delete; // expected-note {{here}} + NoDefault(int); +}; +struct Explicit { // expected-note {{candidate}} expected-note {{here}} + explicit Explicit(int); +}; +struct NoCopy { + NoCopy(); + NoCopy(const NoCopy &) = delete; // expected-note {{here}} +}; +struct NoMove { + NoMove(); + NoMove(NoMove &&) = delete; // expected-note {{here}} +}; +class Private { + Private(int); // expected-note {{here}} +public: + Private(); +}; +class Friend { + friend class S; + Friend(int); +}; + + +class S { + NoDefault nd1; + NoDefault nd2 = 42; + Explicit e1; // expected-note {{here}} + Explicit e2 = 42; // expected-error {{no viable conversion}} + NoCopy nc = NoCopy(); // expected-error {{call to deleted}} + NoMove nm = NoMove(); // expected-error {{call to deleted}} + Private p = 42; // expected-error {{private constructor}} + Friend f = 42; + + S() {} // expected-error {{call to deleted constructor of 'NoDefault'}} \ + expected-error {{must explicitly initialize the member 'e1' which does not have a default constructor}} + S(int) : nd1(42), e1(42) {} +}; + +// FIXME: test the other forms which use copy-initialization diff --git a/test/CXX/dcl.decl/dcl.init/p6.cpp b/test/CXX/dcl.decl/dcl.init/p6.cpp index da6f5b5..514fd0c 100644 --- a/test/CXX/dcl.decl/dcl.init/p6.cpp +++ b/test/CXX/dcl.decl/dcl.init/p6.cpp @@ -14,3 +14,15 @@ void test_const_default_init() { const HasUserDefault x2; const int x3; // expected-error{{default initialization of an object of const type 'const int'}} } + +// rdar://8501008 +struct s0 {}; +struct s1 { static const s0 foo; }; +const struct s0 s1::foo; // expected-error{{default initialization of an object of const type 'const struct s0' requires a user-provided default constructor}} + +template<typename T> +struct s2 { + static const s0 foo; +}; + +template<> const struct s0 s2<int>::foo; // okay |