diff options
Diffstat (limited to 'test')
21 files changed, 602 insertions, 26 deletions
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 0000000000..78560e2d5d --- /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/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p4.cpp index 34a1784007..8a68e4bcd7 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 09245cfd20..fabfb5329d 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/p3-0x.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp index 8b278bf2a2..b93e8e35b1 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 @@ -7,8 +7,8 @@ template<typename T> using Y = struct { // expected-error {{can not be defined i 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 0000000000..9b92340fa4 --- /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 0000000000..e5b5889954 --- /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/except/except.spec/p14.cpp b/test/CXX/except/except.spec/p14.cpp index f5e83eaac6..f42fbe907f 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/expr/expr.prim/p12-0x.cpp b/test/CXX/expr/expr.prim/p12-0x.cpp new file mode 100644 index 0000000000..0ff29a1882 --- /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 0000000000..13735fab4a --- /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/special/class.ctor/p5-0x.cpp b/test/CXX/special/class.ctor/p5-0x.cpp new file mode 100644 index 0000000000..2123d16623 --- /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.init/class.base.init/p8-0x.cpp b/test/CXX/special/class.init/class.base.init/p8-0x.cpp new file mode 100644 index 0000000000..8512a9f7bb --- /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 0000000000..039b1c271a --- /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/CodeGenCXX/member-init-ctor.cpp b/test/CodeGenCXX/member-init-ctor.cpp new file mode 100644 index 0000000000..d9a6734b31 --- /dev/null +++ b/test/CodeGenCXX/member-init-ctor.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 %s -std=c++0x -emit-llvm -o - | FileCheck %s + +bool b(); +struct S { + int n = b() ? S().n + 1 : 0; +}; + +S s; + +// CHECK: define{{.*}} void @_ZN1SC2Ev( +// CHECK-NOT } +// CHECK: call {{.*}} @_Z1bv() +// CHECK-NOT } +// CHECK: call {{.*}} @_ZN1SC1Ev( diff --git a/test/CodeGenObjCXX/blocks.mm b/test/CodeGenObjCXX/blocks.mm index ffb916bf03..e220753ff7 100644 --- a/test/CodeGenObjCXX/blocks.mm +++ b/test/CodeGenObjCXX/blocks.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -x objective-c++ -fblocks -triple x86_64-apple-darwin %s +// RUN: %clang_cc1 -x objective-c++ -fblocks -triple x86_64-apple-darwin %s -verify -emit-llvm -o %t // rdar://8979379 @interface A @@ -28,3 +28,19 @@ void foo(id <NSObject>(^objectCreationBlock)(void)) { return bar(objectCreationBlock); } +// Test4 +struct S { + S *(^a)() = ^{ // expected-warning {{C++0x}} + return this; + }; +}; +S s; + +// Test5 +struct X { + void f() { + ^ { + struct Nested { Nested *ptr = this; }; // expected-warning {{C++0x}} + } (); + }; +}; diff --git a/test/PCH/cxx-member-init.cpp b/test/PCH/cxx-member-init.cpp new file mode 100644 index 0000000000..70392a2832 --- /dev/null +++ b/test/PCH/cxx-member-init.cpp @@ -0,0 +1,22 @@ +// Test this without pch. +// RUN: %clang_cc1 -x c++ -std=c++0x -DHEADER -DSOURCE -fsyntax-only -emit-llvm -o - %s + +// Test with pch. +// RUN: %clang_cc1 -x c++ -std=c++0x -DHEADER -emit-pch -o %t %s +// RUN: %clang_cc1 -x c++ -std=c++0x -DHEADER -include-pch %t -fsyntax-only -emit-llvm -o - %s + +#ifdef HEADER +int n; +struct S { + int *p = &m; + int &m = n; + S *that = this; +}; +#endif + +#ifdef SOURCE +S s; +#elif HEADER +#undef HEADER +#define SOURCE +#endif diff --git a/test/Parser/cxx0x-member-initializers.cpp b/test/Parser/cxx0x-member-initializers.cpp new file mode 100644 index 0000000000..6c3492ef21 --- /dev/null +++ b/test/Parser/cxx0x-member-initializers.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +// Make sure we don't run off the end of the stream when parsing a deferred +// initializer. +int a; // expected-note {{previous}} +struct S { + int n = 4 + ; // expected-error {{expected expression}} +} a; // expected-error {{redefinition}} + +// Make sure we use all of the tokens. +struct T { + int a = 1 // expected-error {{expected ';' at end of declaration list}} + int b = 2; + int c = b; // expected-error {{undeclared identifier}} +}; diff --git a/test/SemaCXX/PR9572.cpp b/test/SemaCXX/PR9572.cpp index d1b70778d0..25c0c017b7 100644 --- a/test/SemaCXX/PR9572.cpp +++ b/test/SemaCXX/PR9572.cpp @@ -1,13 +1,13 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s class Base { - virtual ~Base(); + virtual ~Base(); // expected-note {{implicitly declared private here}} }; -struct Foo : public Base { - const int kBlah = 3; // expected-error{{fields can only be initialized in constructors}} +struct Foo : public Base { // expected-error {{base class 'Base' has private destructor}} + const int kBlah = 3; // expected-warning {{accepted as a C++0x extension}} Foo(); }; struct Bar : public Foo { - Bar() { } + Bar() { } // expected-note {{implicit default destructor for 'Foo' first required here}} }; struct Baz { Foo f; diff --git a/test/SemaCXX/class.cpp b/test/SemaCXX/class.cpp index 52140cb074..44fa0ce7ec 100644 --- a/test/SemaCXX/class.cpp +++ b/test/SemaCXX/class.cpp @@ -34,7 +34,7 @@ public: enum E1 { en1, en2 }; - int i = 0; // expected-error {{fields can only be initialized in constructors}} + int i = 0; // expected-warning {{in-class initialization of non-static data member accepted as a C++0x extension}} static int si = 0; // expected-error {{non-const static data member must be initialized out of line}} static const NestedC ci = 0; // expected-error {{static data member of type 'const C::NestedC' must be initialized out of line}} static const int nci = vs; // expected-error {{in-class initializer is not a constant expression}} diff --git a/test/SemaCXX/implicit-exception-spec.cpp b/test/SemaCXX/implicit-exception-spec.cpp new file mode 100644 index 0000000000..81babc043f --- /dev/null +++ b/test/SemaCXX/implicit-exception-spec.cpp @@ -0,0 +1,63 @@ +// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++0x -Wall %s + +template<bool b> struct ExceptionIf { static int f(); }; +template<> struct ExceptionIf<false> { typedef int f; }; + +// The exception specification of a defaulted default constructor depends on +// the contents of in-class member initializers. However, the in-class member +// initializers can depend on the exception specification of the constructor, +// since the class is considered complete within them. We reject any such cases. +namespace InClassInitializers { + // Noexcept::Noexcept() is implicitly declared as noexcept(false), because it + // directly invokes ThrowSomething(). However... + // + // If noexcept(Noexcept()) is false, then Noexcept() is a constant expression, + // so noexcept(Noexcept()) is true. But if noexcept(Noexcept()) is true, then + // Noexcept::Noexcept is not declared constexpr, therefore noexcept(Noexcept()) + // is false. + bool ThrowSomething() noexcept(false); + struct ConstExpr { + bool b = noexcept(ConstExpr()) && ThrowSomething(); // expected-error {{exception specification is not available until end of class definition}} + }; + // We can use it now. + bool w = noexcept(ConstExpr()); + + // Much more obviously broken: we can't parse the initializer without already + // knowing whether it produces a noexcept expression. + struct TemplateArg { + int n = ExceptionIf<noexcept(TemplateArg())>::f(); // expected-error {{exception specification is not available until end of class definition}} + }; + bool x = noexcept(TemplateArg()); + + // And within a nested class. + struct Nested { + struct Inner { + int n = ExceptionIf<noexcept(Nested())>::f(); // expected-error {{exception specification is not available until end of class definition}} + } inner; + }; + bool y = noexcept(Nested()); + bool z = noexcept(Nested::Inner()); +} + +// FIXME: +// The same problem arises in delayed parsing of exception specifications, +// which clang does not yet support. +namespace ExceptionSpecification { + struct Nested { // expected-note {{not complete}} + struct T { + T() noexcept(!noexcept(Nested())); // expected-error {{incomplete type}} + } t; + }; +} + +// FIXME: +// The same problem arises in delayed parsing of default arguments, +// which clang does not yet support. +namespace DefaultArgument { + // FIXME: this diagnostic is completely wrong. + struct Default { // expected-note {{explicitly marked deleted here}} + struct T { + T(int = ExceptionIf<noexcept(Default())::f()); // expected-error {{call to deleted constructor}} + } t; + }; +} diff --git a/test/SemaCXX/member-init.cpp b/test/SemaCXX/member-init.cpp new file mode 100644 index 0000000000..1b8c523e45 --- /dev/null +++ b/test/SemaCXX/member-init.cpp @@ -0,0 +1,50 @@ +// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++0x -Wall %s + +struct Bitfield { + int n : 3 = 7; // expected-error {{bitfield member cannot have an in-class initializer}} +}; + +int a; +class NoWarning { + int &n = a; +public: + int &GetN() { return n; } +}; + +bool b(); +int k; +struct Recurse { + int &n = b() ? Recurse().n : k; // ok +}; + +struct UnknownBound { + int as[] = { 1, 2, 3 }; // expected-error {{array bound cannot be deduced from an in-class initializer}} + int bs[4] = { 4, 5, 6, 7 }; + int cs[] = { 8, 9, 10 }; // expected-error {{array bound cannot be deduced from an in-class initializer}} +}; + +template<int n> struct T { static const int B; }; +template<> struct T<2> { template<int C, int D> using B = int; }; +const int C = 0, D = 0; +struct S { + int as[] = { decltype(x)::B<C, D>(0) }; // expected-error {{array bound cannot be deduced from an in-class initializer}} + T<sizeof(as) / sizeof(int)> x; // expected-error {{requires a type specifier}} +}; + +struct ThrowCtor { ThrowCtor(int) noexcept(false); }; +struct NoThrowCtor { NoThrowCtor(int) noexcept(true); }; + +struct Throw { ThrowCtor tc = 42; }; +struct NoThrow { NoThrowCtor tc = 42; }; + +static_assert(!noexcept(Throw()), "incorrect exception specification"); +static_assert(noexcept(NoThrow()), "incorrect exception specification"); + +struct CheckExcSpec { + CheckExcSpec() noexcept(true) = default; + int n = 0; +}; +struct CheckExcSpecFail { + CheckExcSpecFail() noexcept(true) = default; // expected-error {{exception specification of explicitly defaulted default constructor does not match the calculated one}} + ThrowCtor tc = 123; +}; diff --git a/test/SemaCXX/type-traits.cpp b/test/SemaCXX/type-traits.cpp index c3470d4c16..30cc6a3f1c 100644 --- a/test/SemaCXX/type-traits.cpp +++ b/test/SemaCXX/type-traits.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++0x %s #define T(b) (b) ? 1 : -1 #define F(b) (b) ? -1 : 1 @@ -38,8 +38,7 @@ typedef Derives DerivesArNB[]; struct DerivesEmpty : Empty {}; struct HasCons { HasCons(int); }; struct HasCopyAssign { HasCopyAssign operator =(const HasCopyAssign&); }; -struct HasMoveAssign { HasMoveAssign operator =(const HasMoveAssign&&); }; // \ - // expected-warning {{rvalue references}} +struct HasMoveAssign { HasMoveAssign operator =(const HasMoveAssign&&); }; struct HasDest { ~HasDest(); }; class HasPriv { int priv; }; class HasProt { protected: int prot; }; @@ -1069,7 +1068,7 @@ struct HasCopy { }; struct HasMove { - HasMove(HasMove&& cp); // expected-warning {{rvalue references}} + HasMove(HasMove&& cp); }; struct HasTemplateCons { @@ -1253,6 +1252,9 @@ void has_nothrow_copy() { { int arr[F(__has_nothrow_copy(cvoid))]; } } +template<bool b> struct assert_expr; +template<> struct assert_expr<true> {}; + void has_nothrow_constructor() { { int arr[T(__has_nothrow_constructor(Int))]; } { int arr[T(__has_nothrow_constructor(IntAr))]; } @@ -1280,6 +12 |