diff options
Diffstat (limited to 'test/CXX')
48 files changed, 1325 insertions, 44 deletions
diff --git a/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp b/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp index 1e5a823663ca..ccadf416c977 100644 --- a/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp +++ b/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp @@ -45,6 +45,9 @@ namespace Test { namespace test1 { template <class T> class A { template <class U> friend void foo(A &, U); // expected-note {{not viable: 1st argument ('const A<int>') would lose const qualifier}} + + public: + A(); }; void test() { diff --git a/test/CXX/class.access/class.friend/p2-cxx03.cpp b/test/CXX/class.access/class.friend/p2-cxx03.cpp index 0391c4b989d2..82cddc2bad50 100644 --- a/test/CXX/class.access/class.friend/p2-cxx03.cpp +++ b/test/CXX/class.access/class.friend/p2-cxx03.cpp @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s template<typename T> class X0 { - friend T; // expected-warning{{non-class type 'T' cannot be a friend}} + friend T; // expected-warning{{non-class friend type 'T' is a C++0x extension}} }; class X1 { }; diff --git a/test/CXX/class.access/p4.cpp b/test/CXX/class.access/p4.cpp index 4228a44fc122..add3635fa63f 100644 --- a/test/CXX/class.access/p4.cpp +++ b/test/CXX/class.access/p4.cpp @@ -96,7 +96,7 @@ namespace test2 { A a; // expected-error {{calling a private constructor}} A A::foo; // okay - class B : A { }; // expected-error {{base class 'test2::A' has private constructor}} + class B : A { }; // expected-error {{base class 'test2::A' has private default constructor}} B b; // expected-note{{implicit default constructor}} class C : virtual A { @@ -104,7 +104,7 @@ namespace test2 { C(); }; - class D : C { }; // expected-error {{inherited virtual base class 'test2::A' has private constructor}} + class D : C { }; // expected-error {{inherited virtual base class 'test2::A' has private default constructor}} D d; // expected-note{{implicit default constructor}} } @@ -206,7 +206,7 @@ namespace test5 { class Test1 { A a; }; // expected-error {{private member}} void test1() { - Test1 a; + Test1 a; a = Test1(); // expected-note{{implicit default copy}} } diff --git a/test/CXX/class/class.friend/p2.cpp b/test/CXX/class/class.friend/p2.cpp index eb5036f81287..87b69c095fbd 100644 --- a/test/CXX/class/class.friend/p2.cpp +++ b/test/CXX/class/class.friend/p2.cpp @@ -4,7 +4,7 @@ struct B0; class A { friend class B {}; // expected-error {{cannot define a type in a friend declaration}} - friend int; // expected-warning {{non-class type 'int' cannot be a friend}} - friend B0; // expected-warning {{must specify 'struct' to befriend}} + friend int; // expected-warning {{non-class friend type 'int' is a C++0x extension}} + friend B0; // expected-warning {{specify 'struct' to befriend 'B0'}} friend class C; // okay }; diff --git a/test/CXX/class/class.mem/p1b.cpp b/test/CXX/class/class.mem/p1b.cpp index d3493f6fd7be..3e8c98530599 100644 --- a/test/CXX/class/class.mem/p1b.cpp +++ b/test/CXX/class/class.mem/p1b.cpp @@ -16,7 +16,7 @@ public: void a3(int a = 42); - // CHEKC: error: use of undeclared identifier 'first' + // CHECK: error: use of undeclared identifier 'first' void a4(int a = first); // expected-error{{use of undeclared identifier 'first'}} class B { diff --git a/test/CXX/class/class.mem/p5-0x.cpp b/test/CXX/class/class.mem/p5-0x.cpp new file mode 100644 index 000000000000..78560e2d5daa --- /dev/null +++ b/test/CXX/class/class.mem/p5-0x.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +int f(); + +struct S +{ + int a = f(); // ok + int b = g(); // expected-error {{use of undeclared identifier 'g'}} +}; diff --git a/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp b/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp index 198b0135187e..e3d3d683ceb7 100644 --- a/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp +++ b/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp @@ -3,7 +3,7 @@ namespace NIL {} // expected-note {{previous definition}} inline namespace NIL {} // expected-error {{cannot be reopened as inline}} inline namespace IL {} // expected-note {{previous definition}} -namespace IL {} // expected-error {{cannot be reopened as non-inline}} +namespace IL {} // expected-warning{{inline namespace cannot be re-opened as a non-inline namespace}} namespace {} // expected-note {{previous definition}} inline namespace {} // expected-error {{cannot be reopened as inline}} diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p1.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p1.cpp new file mode 100644 index 000000000000..40917b8ae3dc --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p1.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// A storage-class-specifier shall not be specified in an explicit +// specialization (14.7.3) or an explicit instantiation (14.7.2) +// directive. +template<typename T> void f(T) {} +template<typename T> static void g(T) {} + + +template<> static void f<int>(int); // expected-error{{explicit specialization cannot have a storage class}} +template static void f<float>(float); // expected-error{{explicit instantiation cannot have a storage class}} + +template<> void f<double>(double); +template void f<long>(long); + +template<> static void g<int>(int); // expected-error{{explicit specialization cannot have a storage class}} +template static void g<float>(float); // expected-error{{explicit instantiation cannot have a storage class}} + +template<> void g<double>(double); +template void g<long>(long); + +template<typename T> +struct X { + static int value; +}; + +template<typename T> +int X<T>::value = 17; + +template static int X<int>::value; // expected-error{{explicit instantiation cannot have a storage class}} + +template<> static int X<float>::value; // expected-error{{'static' can only be specified inside the class definition}} diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp index 34a178400706..8a68e4bcd795 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp @@ -22,14 +22,21 @@ void f() { new const auto (0); new (auto) (0.0); -#if 0 - // When clang supports for-range: - for (auto i : {1,2,3}) { + int arr[] = {1, 2, 3}; + for (auto i : arr) { } - - // When clang supports inline initialization of members. - class X { - static const auto &n = 'x'; - }; -#endif } + +class X { + static const auto n = 'x'; + + auto m = 0; // expected-error {{'auto' not allowed in non-static class member}} +}; + +struct S { + static const auto a; // expected-error {{declaration of variable 'a' with type 'auto const' requires an initializer}} + static const auto b = 0; + static const int c; +}; +const int S::b; +const auto S::c = 0; diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp index 09245cfd2000..fabfb5329da1 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp @@ -3,13 +3,13 @@ struct S { virtual ~S(); - auto a; // expected-error{{'auto' not allowed in struct member}} - auto *b; // expected-error{{'auto' not allowed in struct member}} - const auto c; // expected-error{{'auto' not allowed in struct member}} + auto a; // expected-error{{'auto' not allowed in non-static struct member}} + auto *b; // expected-error{{'auto' not allowed in non-static struct member}} + const auto c; // expected-error{{'auto' not allowed in non-static struct member}} void f() throw (auto); // expected-error{{'auto' not allowed here}} - friend auto; // expected-error{{'auto' not allowed in struct member}} + friend auto; // expected-error{{'auto' not allowed in non-static struct member}} operator auto(); // expected-error{{'auto' not allowed here}} }; diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp new file mode 100644 index 000000000000..81204d89a697 --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p2-0x.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +struct A { typedef int type; }; +template<typename T> using X = A; // expected-note {{declared here}} +struct X<int>* p2; // expected-error {{elaborated type refers to a type alias template}} + + +template<typename T> using Id = T; // expected-note {{declared here}} +template<template<typename> class F> +struct Y { + struct F<int> i; // expected-error {{elaborated type refers to a type alias template}} + typename F<A>::type j; // ok + + // FIXME: don't produce the diagnostic both for the definition and the instantiation. + template<typename T> using U = F<char>; // expected-note 2{{declared here}} + struct Y<F>::template U<char> k; // expected-error 2{{elaborated type refers to a type alias template}} + typename Y<F>::template U<char> l; // ok +}; +template struct Y<Id>; // expected-note {{requested here}} diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp index 10184a058f17..b93e8e35b139 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp @@ -1,15 +1,14 @@ // RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s -// FIXME: when clang supports alias-declarations. -#if 0 using X = struct { // ok }; -#endif +template<typename T> using Y = struct { // expected-error {{can not be defined in a type alias template}} +}; class K { virtual ~K(); - // FIXME: the diagnostic here isn't very good - operator struct S {} (); // expected-error 2{{}} + // FIXME: the diagnostic here is really bad + operator struct S {} (); // expected-error 2{{}} expected-note {{}} }; void f() { 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 000000000000..9b92340fa457 --- /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 000000000000..e5b58899545c --- /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 da6f5b5369d0..514fd0c9b620 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 diff --git a/test/CXX/except/except.spec/p1.cpp b/test/CXX/except/except.spec/p1.cpp index 0559285e77a9..86924bb49d75 100644 --- a/test/CXX/except/except.spec/p1.cpp +++ b/test/CXX/except/except.spec/p1.cpp @@ -58,3 +58,16 @@ namespace noex { void g2(bool b) noexcept(b); // expected-error {{argument to noexcept specifier must be a constant expression}} } + +namespace noexcept_unevaluated { + template<typename T> void f(T) { + T* x = 1; + } + + template<typename T> + void g(T x) noexcept((f(x), sizeof(T) == 4)) { } + + void h() { + g(1); + } +} diff --git a/test/CXX/except/except.spec/p14.cpp b/test/CXX/except/except.spec/p14.cpp index f5e83eaac618..f42fbe907ffe 100644 --- a/test/CXX/except/except.spec/p14.cpp +++ b/test/CXX/except/except.spec/p14.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -verify %s +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -verify -std=c++0x %s struct A { }; struct B { }; struct C { }; @@ -27,3 +27,15 @@ void test_CA() { CA2 &(CA2::*captr3)(const CA2&) throw(A) = &CA2::operator=; // expected-error{{target exception specification is not superset of source}} CA2 &(CA2::*captr4)(const CA2&) throw(B) = &CA2::operator=; // expected-error{{target exception specification is not superset of source}} } + +// In-class member initializers. +struct IC0 { + int inClassInit = 0; +}; +struct IC1 { + int inClassInit = (throw B(), 0); +}; +// FIXME: the exception specification on the default constructor is wrong: +// we cannot currently compute the set of thrown types. +static_assert(noexcept(IC0()), "IC0() does not throw"); +static_assert(!noexcept(IC1()), "IC1() throws"); diff --git a/test/CXX/except/except.spec/p9-dynamic.cpp b/test/CXX/except/except.spec/p9-dynamic.cpp index 490d2fa21f99..3f496f25c9ba 100644 --- a/test/CXX/except/except.spec/p9-dynamic.cpp +++ b/test/CXX/except/except.spec/p9-dynamic.cpp @@ -7,5 +7,5 @@ void target() throw(int) // CHECK: invoke void @_Z8externalv() external(); } -// CHECK: call i32 (i8*, i8*, ...)* @llvm.eh.selector({{.*}} i8* bitcast (i8** @_ZTIi to i8*), i8* null) nounwind +// CHECK: call i32 (i8*, i8*, ...)* @llvm.eh.selector({{.*}} i8* bitcast (i8** @_ZTIi to i8*)) nounwind // CHECK: call void @__cxa_call_unexpected diff --git a/test/CXX/expr/expr.const/p2-0x.cpp b/test/CXX/expr/expr.const/p2-0x.cpp new file mode 100644 index 000000000000..1b38cf19b42e --- /dev/null +++ b/test/CXX/expr/expr.const/p2-0x.cpp @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++0x -verify %s + +// PR9999 +template<bool v> +class bitWidthHolding { +public: + static const + unsigned int width = (v == 0 ? 0 : bitWidthHolding<(v >> 1)>::width + 1); +}; + +static const int width=bitWidthHolding<255>::width; + +template<bool b> +struct always_false { + static const bool value = false; +}; + +template<bool b> +struct and_or { + static const bool and_value = b && and_or<always_false<b>::value>::and_value; + static const bool or_value = !b || and_or<always_false<b>::value>::or_value; +}; + +static const bool and_value = and_or<true>::and_value; +static const bool or_value = and_or<true>::or_value; diff --git a/test/CXX/expr/expr.post/expr.call/p7-0x.cpp b/test/CXX/expr/expr.post/expr.call/p7-0x.cpp new file mode 100644 index 000000000000..bb4726dd3309 --- /dev/null +++ b/test/CXX/expr/expr.post/expr.call/p7-0x.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +struct X1 { + X1(); +}; + +struct X2 { + X2(); + ~X2(); +}; + +void vararg(...); + +void f(X1 x1, X2 x2) { + vararg(x1); // okay + vararg(x2); // expected-error{{cannot pass object of non-trivial type 'X2' through variadic function; call will abort at runtime}} +} diff --git a/test/CXX/expr/expr.prim/p12-0x.cpp b/test/CXX/expr/expr.prim/p12-0x.cpp new file mode 100644 index 000000000000..0ff29a18825b --- /dev/null +++ b/test/CXX/expr/expr.prim/p12-0x.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +struct S { + int *j = &nonexistent; // expected-error {{use of undeclared identifier 'nonexistent'}} + int *m = &n; // ok + + int n = f(); // ok + int f(); +}; + +int i = sizeof(S::m); // ok +int j = sizeof(S::m + 42); // ok diff --git a/test/CXX/expr/expr.prim/p4-0x.cpp b/test/CXX/expr/expr.prim/p4-0x.cpp new file mode 100644 index 000000000000..13735fab4a9d --- /dev/null +++ b/test/CXX/expr/expr.prim/p4-0x.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +struct S { + S *p = this; // ok + decltype(this) q; // expected-error {{invalid use of 'this' outside of a nonstatic member function}} \ + expected-error {{C++ requires a type specifier for all declarations}} + + int arr[sizeof(this)]; // expected-error {{invalid use of 'this' outside of a nonstatic member function}} + int sz = sizeof(this); // ok +}; diff --git a/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp b/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp index 28ed62c71ec0..6d1e523b51bf 100644 --- a/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp +++ b/test/CXX/expr/expr.unary/expr.unary.noexcept/sema.cpp @@ -97,6 +97,8 @@ struct Bad2 { void operator delete(void*) throw(int); }; +typedef int X; + void implicits() { N(new int); P(new (0) int); @@ -113,6 +115,7 @@ void implicits() { N(static_cast<int>(s)); P(static_cast<float>(s)); N(Bad1()); + P(X().~X()); } struct V { @@ -155,12 +158,16 @@ void gencon() { N(G3()); } +template <class T> void f(T&&) noexcept; template <typename T, bool b> void late() { B(b, typeid(*(T*)0)); B(b, T(1)); B(b, static_cast<T>(S2(0, 0))); B(b, S1() + T()); + P(f(T())); + P(new (0) T); + P(delete (T*)0); } struct S3 { virtual ~S3() throw(); @@ -168,9 +175,15 @@ struct S3 { explicit S3(int); S3(const S2&); }; +template <class T> T&& f2() noexcept; +template <typename T> +void late2() { + P(dynamic_cast<S3&>(f2<T&>())); +} void operator +(const S1&, float) throw(); void operator +(const S1&, const S3&); void tlate() { late<float, true>(); late<S3, false>(); + late2<S3>(); } diff --git a/test/CXX/special/class.ctor/p5-0x.cpp b/test/CXX/special/class.ctor/p5-0x.cpp new file mode 100644 index 000000000000..2123d1662358 --- /dev/null +++ b/test/CXX/special/class.ctor/p5-0x.cpp @@ -0,0 +1,173 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x + +struct DefaultedDefCtor1 {}; +struct DefaultedDefCtor2 { DefaultedDefCtor2() = default; }; +struct DeletedDefCtor { DeletedDefCtor() = delete; DeletedDefCtor(int); }; +class PrivateDefCtor { PrivateDefCtor() = default; public: PrivateDefCtor(int); }; +struct DeletedDtor { ~DeletedDtor() = delete; }; +class PrivateDtor { ~PrivateDtor() = default; }; +class Friend { + Friend() = default; ~Friend() = default; + friend struct NotDeleted6c; + friend struct NotDeleted7i; + friend struct NotDeleted7j; + friend struct NotDeleted7k; +}; +struct UserProvidedDefCtor { UserProvidedDefCtor() {} }; +int n; + + +// A defaulted default constructor for a class X is defined as deleted if: + +// - X is a union-like class that has a variant member with a non-trivial +// default constructor, +union Deleted1a { UserProvidedDefCtor u; }; // expected-note {{deleted here}} +Deleted1a d1a; // expected-error {{deleted constructor}} +// FIXME: treating this as having a deleted default constructor is probably a +// bug in the standard. +union Deleted1b { UserProvidedDefCtor u = UserProvidedDefCtor(); }; // expected-note {{deleted here}} +Deleted1b d1b; // expected-error {{deleted constructor}} +union NotDeleted1a { DefaultedDefCtor1 nu; }; +NotDeleted1a nd1a; +// FIXME: clang implements the pre-FDIS rule, under which DefaultedDefCtor2's +// default constructor is non-trivial. +union NotDeleted1b { DefaultedDefCtor2 nu; }; // unexpected-note {{deleted here}} +NotDeleted1b nd1b; // unexpected-error {{deleted constructor}} + +// - any non-static data member with no brace-or-equal-initializer is of +// reference type, +class Deleted2a { Deleted2a() = default; int &a; }; // expected-note {{deleted here}} +Deleted2a d2a; // expected-error {{deleted constructor}} +class NotDeleted2a { int &a = n; }; +NotDeleted2a nd2a; +class NotDeleted2b { int &a = error; }; // expected-error {{undeclared identifier}} +NotDeleted2b nd2b; + +// - 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 +// default constructor, +class Deleted3a { const int a; }; // expected-note {{here}} \ + expected-warning {{does not declare any constructor}} \ + expected-note {{will never be initialized}} +Deleted3a d3a; // expected-error {{deleted constructor}} +class Deleted3b { const DefaultedDefCtor1 a[42]; }; // expected-note {{here}} +Deleted3b d3b; // expected-error {{deleted constructor}} +// FIXME: clang implements the pre-FDIS rule, under which DefaultedDefCtor2's +// default constructor is user-provided. +class Deleted3c { const DefaultedDefCtor2 a; }; // desired-note {{here}} +Deleted3c d3c; // desired-error {{deleted constructor}} +class NotDeleted3a { const int a = 0; }; +NotDeleted3a nd3a; +class NotDeleted3b { const DefaultedDefCtor1 a[42] = {}; }; +NotDeleted3b nd3b; +class NotDeleted3c { const DefaultedDefCtor2 a = DefaultedDefCtor2(); }; +NotDeleted3c nd3c; +union NotDeleted3d { const int a; int b; }; +NotDeleted3d nd3d; +// FIXME: this class should not have a deleted default constructor. +union NotDeleted3e { const DefaultedDefCtor1 a[42]; int b; }; // unexpected-note {{here}} +NotDeleted3e nd3e; // unexpected-error {{deleted constructor}} +// FIXME: clang implements the pre-FDIS rule, under which DefaultedDefCtor2 is +// non-trivial. +union NotDeleted3f { const DefaultedDefCtor2 a; int b; }; // unexpected-note {{here}} +NotDeleted3f nd3f; // unexpected-error {{deleted constructor}} + +// - X is a union and all of its variant members are of const-qualified type (or +// array thereof), +union Deleted4a { const int a; const int b; const UserProvidedDefCtor c; }; // expected-note {{here}} +Deleted4a d4a; // expected-error {{deleted constructor}} +union Deleted4b { const int a; int b; }; +Deleted4b d4b; + +// - X is a non-union class and all members of any anonymous union member are of +// const-qualified type (or array thereof), +struct Deleted5a { union { const int a; }; union { int b; }; }; // expected-note {{here}} +Deleted5a d5a; // expected-error {{deleted constructor}} +struct Deleted5b { union { const int a; int b; }; union { const int c; int d; }; }; +Deleted5b d5b; + +// - any direct or virtual base class, or non-static data member with no +// brace-or-equal-initializer, has class type M (or array thereof) and either +// M has no default constructor or overload resolution as applied to M's default +// constructor results in an ambiguity or in a function that is deleted or +// inaccessible from the defaulted default constructor, or +struct Deleted6a : Deleted2a {}; // expected-note {{here}} +Deleted6a d6a; // expected-error {{deleted constructor}} +struct Deleted6b : virtual Deleted2a {}; // expected-note {{here}} +Deleted6b d6b; // expected-error {{deleted constructor}} +struct Deleted6c { Deleted2a a; }; // expected-note {{here}} +Deleted6c d6c; // expected-error {{deleted constructor}} +struct Deleted6d { DeletedDefCtor a; }; // expected-note {{here}} +Deleted6d d6d; // expected-error {{deleted constructor}} +struct NotDeleted6a { DeletedDefCtor a = 0; }; +NotDeleted6a nd6a; +struct Deleted6e { PrivateDefCtor a; }; // expected-note {{here}} +Deleted6e d6e; // expected-error {{deleted constructor}} +struct NotDeleted6b { PrivateDefCtor a = 0; }; +NotDeleted6b nd6b; +struct NotDeleted6c { Friend a; }; +NotDeleted6c nd6c; + +// - any direct or virtual base class or non-static data member has a type with +// a destructor that is deleted or inaccessible from the defaulted default +// constructor. +struct Deleted7a : DeletedDtor {}; // expected-note {{here}} +Deleted7a d7a; // expected-error {{deleted constructor}} +struct Deleted7b : virtual DeletedDtor {}; // expected-note {{here}} +Deleted7b d7b; // expected-error {{deleted constructor}} +struct Deleted7c { DeletedDtor a; }; // expected-note {{here}} +Deleted7c d7c; // expected-error {{deleted constructor}} +struct Deleted7d { DeletedDtor a = {}; }; // expected-note {{here}} +Deleted7d d7d; // expected-error {{deleted constructor}} +struct Deleted7e : PrivateDtor {}; // expected-note {{here}} +Deleted7e d7e; // expected-error {{deleted constructor}} +struct Deleted7f : virtual PrivateDtor {}; // expected-note {{here}} +Deleted7f d7f; // expected-error {{deleted constructor}} +struct Deleted7g { PrivateDtor a; }; // expected-note {{here}} +Deleted7g d7g; // expected-error {{deleted constructor}} +struct Deleted7h { PrivateDtor a = {}; }; // expected-note {{here}} +Deleted7h d7h; // expected-error {{deleted constructor}} +struct NotDeleted7i : Friend {}; +NotDeleted7i d7i; +struct NotDeleted7j : virtual Friend {}; +NotDeleted7j d7j; +struct NotDeleted7k { Friend a; }; +NotDeleted7k d7k; + + +class Trivial { static const int n = 42; }; +static_assert(__has_trivial_constructor(Trivial), "Trivial is nontrivial"); + +// A default constructor is trivial if it is not user-provided and if: +class NonTrivialDefCtor1 { NonTrivialDefCtor1(); }; +static_assert(!__has_trivial_constructor(NonTrivialDefCtor1), "NonTrivialDefCtor1 is trivial"); + +// - its class has no virtual functions (10.3) and no virtual base classes (10.1), and +class NonTrivialDefCtor2 { virtual void f(); }; +static_assert(!__has_trivial_constructor(NonTrivialDefCtor2), "NonTrivialDefCtor2 is trivial"); +class NonTrivialDefCtor3 : virtual Trivial {}; +static_assert(!__has_trivial_constructor(NonTrivialDefCtor3), "NonTrivialDefCtor3 is trivial"); + +// - no non-static data member of its class has a brace-or-equal-initializer, and +class NonTrivialDefCtor4 { int m = 52; }; +static_assert(!__has_trivial_constructor(NonTrivialDefCtor4), "NonTrivialDefCtor4 is trivial"); + +// - all the direct base classes of its class have trivial default constructors, and +class NonTrivialDefCtor5 : NonTrivialDefCtor1 {}; +static_assert(!__has_trivial_constructor(NonTrivialDefCtor5), "NonTrivialDefCtor5 is trivial"); + +// - for all the non-static data members of its class that are of class type (or array thereof), each such class +// has a trivial default constructor. +class NonTrivialDefCtor6 { NonTrivialDefCtor1 t; }; +static_assert(!__has_trivial_constructor(NonTrivialDefCtor6), "NonTrivialDefCtor5 is trivial"); + +// Otherwise, the default constructor is non-trivial. +class Trivial2 { Trivial2() = delete; }; +//static_assert(__has_trivial_constructor(Trivial2), "NonTrivialDefCtor2 is trivial"); +// FIXME: clang implements the pre-FDIS rule, under which this class is non-trivial. +static_assert(!__has_trivial_constructor(Trivial2), "NonTrivialDefCtor2 is trivial"); + +class Trivial3 { Trivial3() = default; }; +//static_assert(__has_trivial_constructor(Trivial3), "NonTrivialDefCtor3 is trivial"); +// FIXME: clang implements the pre-FDIS rule, under which this class is non-trivial. +static_assert(!__has_trivial_constructor(Trivial3), "NonTrivialDefCtor3 is trivial"); diff --git a/test/CXX/special/class.dtor/p3-0x.cpp b/test/CXX/special/class.dtor/p3-0x.cpp new file mode 100644 index 000000000000..6cdd167983bc --- /dev/null +++ b/test/CXX/special/class.dtor/p3-0x.cpp @@ -0,0 +1,177 @@ +// RUN: %clang_cc1 -std=c++0x -fexceptions -fcxx-exceptions -emit-llvm -o - %s | FileCheck %s + +struct A { + ~A(); +}; + +struct B { + ~B() throw(int); +}; + +struct C { + B b; + ~C() {} +}; + +struct D { + ~D() noexcept(false); +}; + +struct E { + D d; + ~E() {} +}; + +void foo() { + A a; + C c; + E e; + // CHECK: invoke {{.*}} @_ZN1ED1Ev + // CHECK: invoke {{.*}} @_ZN1CD1Ev + // CHECK: call {{.*}} @_ZN1AD1Ev +} + +struct F { + D d; + ~F(); +}; +F::~F() noexcept(false) {} + +struct G { + D d; + ~G(); +}; +G::~G() {} + +struct H { + B b; + ~H(); +}; +H::~H() throw(int) {} + +struct I { + B b; + ~I(); +}; +I::~I() {} + +// Template variants. + +template <typename T> +struct TA { + ~TA(); +}; + +template <typename T> +struct TB { + ~TB() throw(int); +}; + +template <typename T> +struct TC { + TB<T> b; + ~TC() {} +}; + +template <typename T> +struct TD { + ~TD() noexcept(false); +}; + +template <typename T> +struct TE { + TD<T> d; + ~TE() {} +}; + +void tfoo() { + TA<int> a; + TC<int> c; + TE<int> e; + // CHECK: invoke {{.*}} @_ZN2TEIiED1Ev + // CHECK: invoke {{.*}} @_ZN2TCIiED1Ev + // CHECK: call {{.*}} @_ZN2TAIiED1Ev +} + +template <typename T> +struct TF { + TD<T> d; + ~TF(); +}; +template <typename T> +TF<T>::~TF() noexcept(false) {} + +template <typename T> +struct TG { + TD<T> d; + ~TG(); +}; +template <typename T> +TG<T>::~TG() {} + +template <typename T> +struct TH { + TB<T> b; + ~TH(); +}; +template <typename T> +TH<T>::~TH() {} + +void tinst() { + TF<int> f; + TG<int> g; + TH<int> h; +} +// CHECK: define linkonce_odr {{.*}} @_ZN2THIiED1Ev +// CHECK: _ZTIi +// CHECK: __cxa_call_unexpected + +struct VX +{ virtual ~VX() {} }; + +struct VY : VX +{ virtual ~VY() {} }; + +template<typename T> +struct TVY : VX +{ virtual ~TVY() {} }; + + +struct VA { + B b; + virtual ~VA() {} +}; + +struct VB : VA +{ virtual ~VB() {} }; + +template<typename T> +struct TVB : VA +{ virtual ~TVB() {} }; + +void tinst2() { + TVY<int> tvy; + TVB<int> tvb; +} + +template <typename T> +struct Sw { + T t; + ~Sw() {} +}; + +void tsw() { + Sw<int> swi; + Sw<B> swb; +} +// CHECK-NOT: define linkonce_odr {{.*}} @_ZN2SwI1BED1Ev({{.*}} nounwind +// CHECK: define linkonce_odr {{.*}} @_ZN2SwI1BED1Ev({{.*}} +// CHECK: _ZTIi +// CHECK: __cxa_call_unexpected +// CHECK: define linkonce_odr {{.*}} @_ZN2SwIiED1Ev({{.*}} nounwind + +template <typename T> +struct TVC : VX +{ virtual ~TVC(); }; +template <typename T> +TVC<T>::~TVC() {} diff --git a/test/CXX/special/class.init/class.base.init/p8-0x.cpp b/test/CXX/special/class.init/class.base.init/p8-0x.cpp new file mode 100644 index 000000000000..8512a9f7bb3a --- /dev/null +++ b/test/CXX/special/class.init/class.base.init/p8-0x.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +int n; +struct S { + int &a; // expected-note 2{{here}} + int &b = n; + + S() {} // expected-error {{constructor for 'S' must explicitly initialize the reference member 'a'}} + S(int) : a(n) {} // ok + S(char) : b(n) {} // expected-error {{constructor for 'S' must explicitly initialize the reference member 'a'}} + S(double) : a(n), b(n) {} // ok +}; + +union U { + int a = 0; + char b = 'x'; + + // FIXME: these should all be rejected + U() {} // desired-error {{at most one member of a union may be initialized}} + U(int) : a(1) {} // desired-error {{at most one member of a union may be initialized}} + U(char) : b('y') {} // desired-error {{at most one member of a union may be initialized}} + U(double) : a(1), b('y') {} // desired-error {{at most one member of a union may be initialized}} +}; diff --git a/test/CXX/special/class.init/class.base.init/p9-0x.cpp b/test/CXX/special/class.init/class.base.init/p9-0x.cpp new file mode 100644 index 000000000000..039b1c271a3d --- /dev/null +++ b/test/CXX/special/class.init/class.base.init/p9-0x.cpp @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++0x %s -O1 -emit-llvm -o - | FileCheck %s + +struct S { + int n = 10; + int m = 2 * n; + + S() {} + S(int a) : n(a) {} + S(int a, int b) : n(a), m(b) {} + + struct T { + T *that = this; + }; +}; + +template<typename T> +struct U { + T *r = &q; + T q = 42; + U *p = this; +}; + +S a; +// CHECK: @a = {{.*}} { i32 10, i32 20 } + +S b(5); +// CHECK: @b = {{.*}} { i32 5, i32 10 } + +S c(3, 9); +// CHECK: @c = {{.*}} { i32 3, i32 9 } + +S::T d; +// CHECK: @d = {{.*}} { {{.*}} @d } + +U<S> e; +// CHECK: @e = {{.*}} { {{.*}} { i32 42, i32 84 }, {{.*}} @e } diff --git a/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp b/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp new file mode 100644 index 000000000000..b41504488e8e --- /dev/null +++ b/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +// PR10034 +struct X {}; + +void exx(X) {} + +int test_ptr10034(int argc, char **argv) +{ + if (argc > 3) + goto end; + + X x; + X xs[16]; + exx(x); + + end: + if (argc > 1) { + for (int i = 0; i < argc; ++i) + { + + } + } + return 0; +} + +struct Y { + ~Y(); +}; + +void f(); +void test_Y() { + goto end; + Y y; + end: + f(); + goto inner; + { + Y y2; + inner: + f(); + } + return; +} + +struct Z { + Z operator=(const Z&); +}; + +void test_Z() { + goto end; + Z z; + end: + return; +} diff --git a/test/CXX/stmt.stmt/stmt.dcl/p3.cpp b/test/CXX/stmt.stmt/stmt.dcl/p3.cpp new file mode 100644 index 000000000000..18fd34039ee5 --- /dev/null +++ b/test/CXX/stmt.stmt/stmt.dcl/p3.cpp @@ -0,0 +1,47 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// PR10034 +struct X {}; + +void exx(X) {} + +int test_ptr10034(int argc, char **argv) +{ + if (argc > 3) + goto end; + + X x; + X xs[16]; + exx(x); + + end: + if (argc > 1) { + for (int i = 0; i < argc; ++i) + { + + } + } + return 0; +} + +struct Y { + ~Y(); +}; + +void test_Y() { + goto end; // expected-error{{goto into protected scope}} + Y y; // expected-note{{jump bypasses variable initialization}} + end: + return; +} + +struct Z { + Z operator=(const Z&); +}; + +void test_Z() { + goto end; // expected-error{{goto into protected scope}} + Z z; // expected-note{{jump bypasses variable initialization}} + end: + return; +} diff --git a/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp b/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp index 12acde143c4f..7bfa6fe58266 100644 --- a/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp +++ b/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp @@ -33,8 +33,8 @@ struct B { int *alt_end(); }; -void f(); // expected-note {{candidate}} -void f(int); // expected-note {{candidate}} +void f(); +void f(int); void g() { for (int a : A()) @@ -44,7 +44,7 @@ void g() { for (char *a : B()) { // expected-error {{cannot initialize a variable of type 'char *' with an lvalue of type 'int'}} } // FIXME: Terrible diagnostic here. auto deduction should fail, but does not! - for (double a : f) { // expected-error {{address of overloaded function 'f' does not match required type '<overloaded function type>'}} + for (double a : f) { // expected-error {{cannot use type '<overloaded function type>' as a range}} } for (auto a : A()) { } diff --git a/test/CXX/temp/temp.decls/p3.cpp b/test/CXX/temp/temp.decls/p3.cpp new file mode 100644 index 000000000000..54800e4061ee --- /dev/null +++ b/test/CXX/temp/temp.decls/p3.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +template<typename T> using A = int; +template<typename T> using A<T*> = char; // expected-error {{partial specialization of alias templates is not permitted}} +template<> using A<char> = char; // expected-error {{explicit specialization of alias templates is not permitted}} +template using A<char> = char; // expected-error {{explicit instantiation of alias templates is not permitted}} +using A<char> = char; // expected-error {{name defined in alias declaration must be an identifier}} diff --git a/test/CXX/temp/temp.decls/temp.alias/p1.cpp b/test/CXX/temp/temp.decls/temp.alias/p1.cpp new file mode 100644 index 000000000000..80079b33a53b --- /dev/null +++ b/test/CXX/temp/temp.decls/temp.alias/p1.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +template<typename T> using U = T; + +// The name of the alias template is a template-name. +U<char> x; +void f(U<int>); +typedef U<U<U<U<int>>>> I; diff --git a/test/CXX/temp/temp.decls/temp.alias/p2.cpp b/test/CXX/temp/temp.decls/temp.alias/p2.cpp new file mode 100644 index 000000000000..e145727a8dd7 --- /dev/null +++ b/test/CXX/temp/temp.decls/temp.alias/p2.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +template<typename T> using U = T; + +using I = U<U<U<U<int>>>>; +using I = int; + +template<typename A, typename B> using Fst = A; +template<typename A, typename B> using Snd = B; + +using I = Fst<Snd<char,int>,double>; + +namespace StdExample { + // Prerequisites for example. + template<class T, class A> struct vector { /* ... */ }; + + + template<class T> struct Alloc {}; + template<class T> using Vec = vector<T, Alloc<T>>; + Vec<int> v; + + template<class T> + void process(Vec<T>& v) // expected-note {{previous definition is here}} + { /* ... */ } + + template<class T> + void process(vector<T, Alloc<T>>& w) // expected-error {{redefinition of 'process'}} + { /* ... */ } + + template<template<class> class TT> + void f(TT<int>); // expected-note {{candidate template ignored}} + + template<template<class,class> class TT> + void g(TT<int, Alloc<int>>); + + int h() { + f(v); // expected-error {{no matching function for call to 'f'}} + g(v); // OK: TT = vector + } + + + // v's type is same as vector<int, Alloc<int>>. + using VTest = vector<int, Alloc<int>>; + using VTest = decltype(v); +} diff --git a/test/CXX/temp/temp.decls/temp.alias/p3.cpp b/test/CXX/temp/temp.decls/temp.alias/p3.cpp new file mode 100644 index 000000000000..2e9e55cdcb6b --- /dev/null +++ b/test/CXX/temp/temp.decls/temp.alias/p3.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +// The example given in the standard (this is rejected for other reasons anyway). +template<class T> struct A; +template<class T> using B = typename A<T>::U; // expected-error {{no type named 'U' in 'A<T>'}} +template<class T> struct A { + typedef B<T> U; // expected-note {{in instantiation of template type alias 'B' requested here}} +}; +B<short> b; + +template<typename T> using U = int; +// FIXME: This is illegal, but probably only because CWG1044 missed this paragraph. +template<typename T> using U = U<T>; diff --git a/test/CXX/temp/temp.decls/temp.friend/p3.cpp b/test/CXX/temp/temp.decls/temp.friend/p3.cpp index d116e016f1d2..0b2a25e9876b 100644 --- a/test/CXX/temp/temp.decls/temp.friend/p3.cpp +++ b/test/CXX/temp/temp.decls/temp.friend/p3.cpp @@ -8,5 +8,5 @@ class B { template <class T> friend class A; template <class T> friend class Undeclared; - template <class T> friend typename A<T>::Member; // expected-warning {{non-class type 'typename A<T>::Member' cannot be a friend}} + template <class T> friend typename A<T>::Member; // expected-error {{friend type templates must use an elaborated type}} }; diff --git a/test/CXX/temp/temp.decls/temp.variadic/ext-blocks.cpp b/test/CXX/temp/temp.decls/temp.variadic/ext-blocks.cpp index 62cf4298f717..7375f98ec9c3 100644 --- a/test/CXX/temp/temp.decls/temp.variadic/ext-blocks.cpp +++ b/test/CXX/temp/temp.decls/temp.variadic/ext-blocks.cpp @@ -37,3 +37,10 @@ int f3(Args ...args) { } template int f3(const char*, int, float, double); + +template<typename ...Args> +int PR9953(Args ...args) { + return ^(Args *...block_args) { + return f1(block_args); // expected-error{{expression contains unexpanded parameter pack 'block_args'}} + }(&args...); +} diff --git a/test/CXX/temp/temp.fct.spec/temp.deduct/cwg1170.cpp b/test/CXX/temp/temp.fct.spec/temp.deduct/cwg1170.cpp new file mode 100644 index 000000000000..d3af0d4b9132 --- /dev/null +++ b/test/CXX/temp/temp.fct.spec/temp.deduct/cwg1170.cpp @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +#if !__has_feature(cxx_access_control_sfinae) +# error No support for access control as part of SFINAE? +#endif + +typedef char yes_type; +typedef char (&no_type)[2]; + +template<unsigned N> struct unsigned_c { }; + +template<typename T> +class has_copy_constructor { + static T t; + + template<typename U> static yes_type check(unsigned_c<sizeof(U(t))> * = 0); + template<typename U> static no_type check(...); + +public: + static const bool value = (sizeof(check<T>(0)) == sizeof(yes_type)); +}; + +struct HasCopy { }; + +struct HasNonConstCopy { + HasNonConstCopy(HasNonConstCopy&); +}; + +struct HasDeletedCopy { + HasDeletedCopy(const HasDeletedCopy&) = delete; +}; + +struct HasPrivateCopy { +private: + HasPrivateCopy(const HasPrivateCopy&); +}; + +int check0[has_copy_constructor<HasCopy>::value? 1 : -1]; +int check1[has_copy_constructor<HasNonConstCopy>::value? 1 : -1]; +int check2[has_copy_constructor<HasDeletedCopy>::value? -1 : 1]; +int check3[has_copy_constructor<HasPrivateCopy>::value? -1 : 1]; diff --git a/test/CXX/temp/temp.param/p10-0x.cpp b/test/CXX/temp/temp.param/p10-0x.cpp new file mode 100644 index 000000000000..bc7e616fb13d --- /dev/null +++ b/test/CXX/temp/temp.param/p10-0x.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +template<typename> struct Y1; +template<typename, int> struct Y2; + +template<class T1, class T2 = int> using B2 = T1; +template<class T1 = int, class T2> using B2 = T1; + +template<template<class> class F, template<class> class G = Y1> using B2t = F<G<int>>; +template<template<class> class F = Y2, template<class> class G> using B2t = F<G<int>>; + +template<int N, int M = 5> using B2n = Y2<int, N + M>; +template<int N = 5, int M> using B2n = Y2<int, N + M>; diff --git a/test/CXX/temp/temp.param/p11-0x.cpp b/test/CXX/temp/temp.param/p11-0x.cpp index 0bf4341cf8d7..10a44380c8d1 100644 --- a/test/CXX/temp/temp.param/p11-0x.cpp +++ b/test/CXX/temp/temp.param/p11-0x.cpp @@ -1,29 +1,48 @@ // RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s -// If a template-parameter of a class template has a default -// template-argument, each subsequent template-parameter shall either -// have a default template-argument supplied or be a template -// parameter pack. +// If a template-parameter of a class template or alias template has a default +// template-argument, each subsequent template-parameter shall either have a +// default template-argument supplied or be a template parameter pack. template<typename> struct vector; +template<typename T = int, typename> struct X3t; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}} +template<typename T = int, typename> using A3t = int; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}} +template<int V = 0, int> struct X3nt; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}} +template<int V = 0, int> using A3nt = int; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}} +template<template<class> class M = vector, template<class> class> struct X3tt; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}} +template<template<class> class M = vector, template<class> class> using A3tt = int; // expected-error{{template parameter missing a default argument}} expected-note{{previous default template argument defined here}} + template<typename T = int, typename ...Types> struct X2t; +template<typename T = int, typename ...Types> using A2t = X2t<T, Types...>; template<int V = 0, int ...Values> struct X2nt; +template<int V = 0, int ...Values> using A2nt = X2nt<V, Values...>; template<template<class> class M = vector, template<class> class... Metas> struct X2tt; +template<template<class> class M = vector, template<class> class... Metas> + using A2tt = X2tt<M, Metas...>; -// If a template-parameter of a primary class template is a template -// parameter pack, it shall be the last template-parameter . +// If a template-parameter of a primary class template or alias template is a +// template parameter pack, it shall be the last template-parameter. template<typename ...Types, // expected-error{{template parameter pack must be the last template parameter}} int After> struct X0t; +template<typename ...Types, // expected-error{{template parameter pack must be the last template parameter}} + int After> +using A0t = int; template<int ...Values, // expected-error{{template parameter pack must be the last template parameter}} int After> struct X0nt; +template<int ...Values, // expected-error{{template parameter pack must be the last template parameter}} + int After> +using A0nt = int; template<template<typename> class ...Templates, // expected-error{{template parameter pack must be the last template parameter}} int After> struct X0tt; +template<template<typename> class ...Templates, // expected-error{{template parameter pack must be the last template parameter}} + int After> +using A0tt = int; // [ Note: These are not requirements for function templates or class // template partial specializations because template arguments can be diff --git a/test/CXX/temp/temp.param/p9-0x.cpp b/test/CXX/temp/temp.param/p9-0x.cpp index 17eca7f7e85d..1dc6640fe266 100644 --- a/test/CXX/temp/temp.param/p9-0x.cpp +++ b/test/CXX/temp/temp.param/p9-0x.cpp @@ -50,3 +50,12 @@ namespace PR8748 { template<typename T = int> struct Inner::X3 { }; template<typename T = int> void Inner::f2() {} } + +namespace PR10069 { + template<typename T, T a, T b=0, T c=1> + T f(T x); + + void g() { + f<unsigned int, 0>(0); + } +} diff --git a/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p1.cpp b/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p1.cpp new file mode 100644 index 000000000000..1d1d350cf337 --- /dev/null +++ b/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p1.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +// Examples from CWG1056. +namespace Example1 { + template<class T> struct A; + template<class T> using B = A<T>; + + template<class T> struct A { + struct C {}; + B<T>::C bc; // ok, B<T> is the current instantiation. + }; + + template<class T> struct A<A<T>> { + struct C {}; + B<B<T>>::C bc; // ok, B<B<T>> is the current instantiation. + }; + + template<class T> struct A<A<A<T>>> { + struct C {}; + B<B<T>>::C bc; // expected-error {{missing 'typename'}} + }; +} + +namespace Example2 { + template<class T> struct A { + void g(); + }; + template<class T> using B = A<T>; + template<class T> void B<T>::g() {} // ok. +} diff --git a/test/CXX/temp/temp.spec/temp.expl.spec/examples.cpp b/test/CXX/temp/temp.spec/temp.expl.spec/examples.cpp new file mode 100644 index 000000000000..f04c544aa448 --- /dev/null +++ b/test/CXX/temp/temp.spec/temp.expl.spec/examples.cpp @@ -0,0 +1,209 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +namespace PR5907 { + template<typename T> struct identity { typedef T type; }; + struct A { A(); }; + identity<A>::type::A() { } + + struct B { void f(); }; + template<typename T> struct C { typedef B type; }; + + void C<int>::type::f() { } +} + +namespace PR9421 { + namespace N { template<typename T> struct S { void f(); }; } + typedef N::S<int> T; + namespace N { template<> void T::f() {} } +} + +namespace PR8277 { + template< typename S > + struct C + { + template< int > + void F( void ) + { + } + }; + + template< typename S > + struct D + { + typedef C< int > A; + }; + + typedef D< int >::A A; + + template<> + template<> + void A::F< 0 >( void ) + { + } +} + +namespace PR8277b { + template<typename S> struct C { + void f(); + }; + template<typename S> struct D { + typedef C<int> A; + }; + template<> void D<int>::A::f() { + } +} + +namespace PR8708 { + template<typename T> struct A { + template<typename U> struct B { + // #2 + void f(); + }; + }; + + // #A specialize the member template for + // implicit instantiation of A<int>, + // leaving the member template "unspecialized" + // (14.7.3/16). Specialization uses the syntax + // for explicit specialization (14.7.3/14) + template<> template<typename U> + struct A<int>::B { + // #1 + void g(); + }; + + // #1 define its function g. There is an enclosing + // class template, so we write template<> for each + // specialized template (14.7.3/15). + template<> template<typename U> + void A<int>::B<U>::g() { } + + // #2 define the unspecialized member template's + // f + template<typename T> template<typename U> + void A<T>::B<U>::f() { } + + + // specialize the member template again, now + // specializing the member too. This specializes + // #A + template<> template<> + struct A<int>::B<int> { + // #3 + void h(); + }; + + // defines #3. There is no enclosing class template, so + // we write no "template<>". + void A<int>::B<int>::h() { } + + void test() { + // calls #1 + A<int>::B<float> a; a.g(); + + // calls #2 + A<float>::B<int> b; b.f(); + + // calls #3 + A<int>::B<int> c; c.h(); + } +} + +namespace PR9482 { + namespace N1 { + template <typename T> struct S { + void foo() {} + }; + } + + namespace N2 { + typedef N1::S<int> X; + } + + namespace N1 { + template<> void N2::X::foo() {} + } +} + +namespace PR9668 { + namespace First + { + template<class T> + class Bar + { + protected: + + static const bool static_bool; + }; + } + + namespace Second + { + class Foo; + } + + typedef First::Bar<Second::Foo> Special; + + namespace + First + { + template<> + const bool Special::static_bool(false); + } +} + +namespace PR9877 { + template<int> + struct X + { + struct Y; + }; + + template<> struct X<0>::Y { static const int Z = 1; }; + template<> struct X<1>::Y { static const int Z = 1; }; + + const int X<0>::Y::Z; + template<> const int X<1>::Y::Z; // expected-error{{extraneous 'template<>' in declaration of variable 'Z'}} +} + +namespace PR9913 { + template<class,class=int>struct S; + template<class X>struct S<X> { + template<class T> class F; + }; + + template<class A> + template<class B> + class S<A>::F{}; +} + +namespace template_class_spec_perClassDecl_nested +{ + template <typename T1> struct A { + template <typename T2> struct B { + template <typename T3> struct C { + static void foo(); + }; + }; + }; + + template <> struct A<int> { + template <typename T2> struct B { + template <typename T3> struct C { + static void foo(); + }; + }; + }; + + template <> template <typename T3> struct A<int>::B<int>::C { + static void foo(); + }; + + template <> template <> struct A<int>::B<int>::C<int> { + static void foo(); + }; + + template <> template<> template <typename T2> struct A<bool>::B<bool>::C { + static void foo(); + }; +} diff --git a/test/CXX/temp/temp.spec/temp.expl.spec/p15.cpp b/test/CXX/temp/temp.spec/temp.expl.spec/p15.cpp index a5ecf5fcd9d2..72f33df7efa4 100644 --- a/test/CXX/temp/temp.spec/temp.expl.spec/p15.cpp +++ b/test/CXX/temp/temp.spec/temp.expl.spec/p15.cpp @@ -20,3 +20,14 @@ NonDefaultConstructible &test(bool b) { return b? X<NonDefaultConstructible, int>::member // expected-note{{instantiation}} : X<NonDefaultConstructible, long>::member; } + +namespace rdar9422013 { + template<int> + struct X { + struct Inner { + static unsigned array[17]; + }; + }; + + template<> unsigned X<1>::Inner::array[]; // okay +} diff --git a/test/CXX/temp/temp.spec/temp.expl.spec/p16.cpp b/test/CXX/temp/temp.spec/temp.expl.spec/p16.cpp index 2f9a3cbf9457..c7597e9f817c 100644 --- a/test/CXX/temp/temp.spec/temp.expl.spec/p16.cpp +++ b/test/CXX/temp/temp.spec/temp.expl.spec/p16.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only %s +// RUN: %clang_cc1 -fsyntax-only -verify %s template<class T> struct A { void f(T); template<class X1> void g1(T, X1); @@ -24,3 +24,15 @@ template<> template<> // member specialization even if defined in class definition template<> void A<int>::h(int) { } + +namespace PR10024 { + template <typename T> + struct Test{ + template <typename U> + void get(U i) {} + }; + + template <typename T> + template <> + void Test<T>::get<double>(double i) {} // expected-error{{cannot specialize (with 'template<>') a member of an unspecialized template}} +} diff --git a/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp b/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp index 88cfc5d7c397..56231e2f725f 100644 --- a/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp +++ b/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp @@ -24,12 +24,11 @@ namespace test1 { template <> class A<double> { public: - static int foo; // expected-note{{attempt to specialize}} + static int foo; static int bar; }; typedef A<double> AB; - template <> int AB::foo = 0; // expected-error{{extraneous 'template<>'}} \ - // expected-error{{does not specialize}} + template <> int AB::foo = 0; // expected-error{{extraneous 'template<>'}} int AB::bar = 1; } diff --git a/test/CXX/temp/temp.spec/temp.expl.spec/p5-example.cpp b/test/CXX/temp/temp.spec/temp.expl.spec/p5-example.cpp new file mode 100644 index 000000000000..f49190ef5ad8 --- /dev/null +++ b/test/CXX/temp/temp.spec/temp.expl.spec/p5-example.cpp @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +template<class T> struct A { + struct B { }; + template<class U> struct C { }; +}; + template<> struct A<int> { + void f(int); +}; +void h() { + A<int> a; + a.f(16); +} +// A<int>::f must be defined somewhere +// template<> not used for a member of an // explicitly specialized class template +void A<int>::f(int) { /* ... */ } + template<> struct A<char>::B { + void f(); +}; +// template<> also not used when defining a member of // an explicitly specialized member class +void A<char>::B::f() { /* ... */ } + template<> template<class U> struct A<char>::C { + void f(); +}; + +template<> +template<class U> void A<char>::C<U>::f() { /* ... */ } + template<> struct A<short>::B { + void f(); +}; +template<> void A<short>::B::f() { /* ... */ } // expected-error{{no function template matches function template specialization 'f'}} + template<> template<class U> struct A<short>::C { + void f(); +}; +template<class U> void A<short>::C<U>::f() { /* ... */ } // expected-error{{template parameter list matching the non-templated nested type 'A<short>' should be empty ('template<>')}} diff --git a/test/CXX/temp/temp.spec/temp.explicit/p2.cpp b/test/CXX/temp/temp.spec/temp.explicit/p2.cpp index 70d338b9f645..822f88171212 100644 --- a/test/CXX/temp/temp.spec/temp.explicit/p2.cpp +++ b/test/CXX/temp/temp.spec/temp.explicit/p2.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s // Example from the standard template<class T> class Array { void mf() { } }; @@ -35,7 +35,7 @@ namespace N { }; template<typename T> - void f1(T) {}; // expected-note{{explicit instantiation refers here}} + void f1(T) {} // expected-note{{explicit instantiation refers here}} } using namespace N; diff --git a/test/CXX/temp/temp.type/p1-0x.cpp b/test/CXX/temp/temp.type/p1-0x.cpp new file mode 100644 index 000000000000..c22af22f9865 --- /dev/null +++ b/test/CXX/temp/temp.type/p1-0x.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +namespace Old { + template<template<class> class TT> struct X { }; + template<class> struct Y { }; + template<class T> using Z = Y<T>; + X<Y> y; + X<Z> z; + + using SameType = decltype(y); // expected-note {{here}} + using SameType = decltype(z); // expected-error {{different types}} +} + +namespace New { + template<class T> struct X { }; + template<class> struct Y { }; + template<class T> using Z = Y<T>; + X<Y<int>> y; + X<Z<int>> z; + + using SameType = decltype(y); + using SameType = decltype(z); // ok +} |