diff options
Diffstat (limited to 'test/CXX/class')
-rw-r--r-- | test/CXX/class/class.friend/p1.cpp | 3 | ||||
-rw-r--r-- | test/CXX/class/class.mem/p1.cpp | 27 | ||||
-rw-r--r-- | test/CXX/class/class.mem/p13.cpp | 40 | ||||
-rw-r--r-- | test/CXX/class/class.mem/p14.cpp | 19 | ||||
-rw-r--r-- | test/CXX/class/class.mem/p1b.cpp | 46 | ||||
-rw-r--r-- | test/CXX/class/class.mem/p8-0x-pedantic.cpp | 14 | ||||
-rw-r--r-- | test/CXX/class/class.mem/p8-0x.cpp | 55 | ||||
-rw-r--r-- | test/CXX/class/class.nest/p1-cxx0x.cpp | 14 | ||||
-rw-r--r-- | test/CXX/class/class.nest/p1.cpp | 6 | ||||
-rw-r--r-- | test/CXX/class/class.union/p1.cpp | 8 | ||||
-rw-r--r-- | test/CXX/class/p1-0x.cpp | 10 | ||||
-rw-r--r-- | test/CXX/class/p2-0x.cpp | 28 |
12 files changed, 266 insertions, 4 deletions
diff --git a/test/CXX/class/class.friend/p1.cpp b/test/CXX/class/class.friend/p1.cpp index 3ad4a5f..bb1af10 100644 --- a/test/CXX/class/class.friend/p1.cpp +++ b/test/CXX/class/class.friend/p1.cpp @@ -57,7 +57,8 @@ class A { friend A operator|(const A& l, const A& r); // okay friend A operator|(const A& r); // expected-error {{ overloaded 'operator|' must be a binary operator (has 1 parameter) }} - friend operator bool() const; // expected-error {{ must use a qualified name when declaring a conversion operator as a friend }} + friend operator bool() const; // expected-error {{ must use a qualified name when declaring a conversion operator as a friend }} \ + // expected-error{{type qualifier is not allowed on this function}} typedef void ftypedef(); friend ftypedef typedeffed_function; // okay (because it's not declared as a member) diff --git a/test/CXX/class/class.mem/p1.cpp b/test/CXX/class/class.mem/p1.cpp index 55507d4..a41f1db 100644 --- a/test/CXX/class/class.mem/p1.cpp +++ b/test/CXX/class/class.mem/p1.cpp @@ -62,3 +62,30 @@ struct S5 }; + +namespace PR8245 { + class X { + public: + template<class C> + class Inner { + public: + void foo(bool bar = true); + int bam; + }; + + Inner<int> _foo; + }; + + void f() { + X::Inner<int> c2i; + X::Inner<float> c2f; + c2i.foo(); + c2f.foo(); + } + + class Y { + class Inner { + void foo(int = sizeof(Y)); + }; + }; +} diff --git a/test/CXX/class/class.mem/p13.cpp b/test/CXX/class/class.mem/p13.cpp new file mode 100644 index 0000000..7cded23 --- /dev/null +++ b/test/CXX/class/class.mem/p13.cpp @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// If T is the name of a class, then each of the following shall have +// a name different from T: + +// - every static data member of class T; +struct X0 { + static int X0; // expected-error{{member 'X0' has the same name as its class}} +}; + +// - every member function of class T +// (Cannot be tested) + +// - every member of class T that is itself a type; +struct X1 { // expected-note{{previous use is here}} + enum X1 { }; // expected-error{{use of 'X1' with tag type that does not match previous declaration}} +}; + +struct X2 { + typedef int X2; // expected-error{{member 'X2' has the same name as its class)}} +}; + +// - every enumerator of every member of class T that is an enumerated type; and +struct X3 { + enum E { + X3 // expected-error{{member 'X3' has the same name as its class}} + }; +}; + +// - every member of every anonymous union that is a member of class T. +struct X4 { + union { + int X; + union { + float Y; + unsigned X4; // expected-error{{member 'X4' has the same name as its class}} + }; + }; +}; + diff --git a/test/CXX/class/class.mem/p14.cpp b/test/CXX/class/class.mem/p14.cpp new file mode 100644 index 0000000..72b232e --- /dev/null +++ b/test/CXX/class/class.mem/p14.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// In addition, if class T has a user-declared constructor (12.1), +// every non-static data member of class T shall have a name different +// from T. + +struct X0 { + int X0; // okay +}; + +struct X1 { + int X1; + X1(); // expected-error{{declarator requires an identifier}} +}; + +struct X2 { + X2(); + float X2; // expected-error{{member 'X2' has the same name as its class}} +}; diff --git a/test/CXX/class/class.mem/p1b.cpp b/test/CXX/class/class.mem/p1b.cpp new file mode 100644 index 0000000..d3493f6 --- /dev/null +++ b/test/CXX/class/class.mem/p1b.cpp @@ -0,0 +1,46 @@ +// The first run checks that the correct errors are generated, +// implicitly checking the order of default argument parsing: +// RUN: %clang_cc1 -fsyntax-only -verify %s +// The second run checks the order of inline method definitions: +// RUN: not %clang_cc1 -fsyntax-only %s 2> %t +// RUN: FileCheck %s < %t + +class A { +public: + void a1() { + B b = B(); + } + + class B; + void a2(B b = B()); // expected-error{{use of default argument to function 'B' that is declared later in class 'B'}} + + void a3(int a = 42); + + // CHEKC: error: use of undeclared identifier 'first' + void a4(int a = first); // expected-error{{use of undeclared identifier 'first'}} + + class B { + public: + B(int b = 42) { // expected-note{{default argument declared here}} + A a; + a.a3(); + a.a6(); + } + + void b1(A a = A()); // expected-error{{use of default argument to function 'A' that is declared later in class 'A'}} + + // CHECK: error: use of undeclared identifier 'second' + void b2(int a = second); // expected-error{{use of undeclared identifier 'second'}} + }; + + void a5() { + B b = B(); + } + + void a6(B b = B()); + + A(int a = 42); // expected-note{{default argument declared here}} + + // CHECK: error: use of undeclared identifier 'third' + void a7(int a = third); // expected-error{{use of undeclared identifier 'third'}} +}; diff --git a/test/CXX/class/class.mem/p8-0x-pedantic.cpp b/test/CXX/class/class.mem/p8-0x-pedantic.cpp new file mode 100644 index 0000000..a4b775c --- /dev/null +++ b/test/CXX/class/class.mem/p8-0x-pedantic.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++0x -pedantic -verify %s + +namespace inline_extension { + struct Base1 { + virtual void f() {} + }; + + struct B : Base1 { + virtual void f() override {} // expected-warning {{'override' keyword only allowed in declarations, allowed as an extension}} + virtual void g() final {} // expected-warning {{'final' keyword only allowed in declarations, allowed as an extension}} + virtual void h() new {} // expected-warning {{'new' keyword only allowed in declarations, allowed as an extension}} + }; +} + diff --git a/test/CXX/class/class.mem/p8-0x.cpp b/test/CXX/class/class.mem/p8-0x.cpp new file mode 100644 index 0000000..bf1b4c1 --- /dev/null +++ b/test/CXX/class/class.mem/p8-0x.cpp @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++0x -verify %s + +struct Base1 { + virtual void g(); +}; + +struct A : Base1 { + virtual void f() new new; // expected-error {{class member already marked 'new'}} + virtual void g() override override; // expected-error {{class member already marked 'override'}} + virtual void h() final final; // expected-error {{class member already marked 'final'}} +}; + +struct Base2 { + virtual void e1(), e2(); + virtual void f(); +}; + +struct B : Base2 { + virtual void e1() override, e2(int); // No error. + virtual void f() override; + void g() override; // expected-error {{only virtual member functions can be marked 'override'}} + int h override; // expected-error {{only virtual member functions can be marked 'override'}} +}; + +struct C { + virtual void f() final; + void g() final; // expected-error {{only virtual member functions can be marked 'final'}} + int h final; // expected-error {{only virtual member functions can be marked 'final'}} +}; + +namespace inline_extension { + struct Base1 { + virtual void g() {} + }; + + struct A : Base1 { + virtual void f() new new {} // expected-error {{class member already marked 'new'}} + virtual void g() override override {} // expected-error {{class member already marked 'override'}} + virtual void h() final final {} // expected-error {{class member already marked 'final'}} + }; + + struct Base2 { + virtual void f(); + }; + + struct B : Base2 { + virtual void f() override {} + void g() override {} // expected-error {{only virtual member functions can be marked 'override'}} + }; + + struct C { + virtual void f() final {} + void g() final {} // expected-error {{only virtual member functions can be marked 'final'}} + }; +} diff --git a/test/CXX/class/class.nest/p1-cxx0x.cpp b/test/CXX/class/class.nest/p1-cxx0x.cpp new file mode 100644 index 0000000..f8b06ac --- /dev/null +++ b/test/CXX/class/class.nest/p1-cxx0x.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++0x -verify %s + +class Outer { + int x; + static int sx; + int f(); + + // The first case is invalid in the C++03 mode but valid in C++0x (see 5.1.1.10). + class Inner { + static char a[sizeof(x)]; // okay + static char b[sizeof(sx)]; // okay + static char c[sizeof(f)]; // expected-error {{ call to non-static member function without an object argument }} + }; +}; diff --git a/test/CXX/class/class.nest/p1.cpp b/test/CXX/class/class.nest/p1.cpp index f1f5496..350cc81 100644 --- a/test/CXX/class/class.nest/p1.cpp +++ b/test/CXX/class/class.nest/p1.cpp @@ -3,12 +3,12 @@ class Outer { int x; static int sx; + int f(); - // C++0x will likely relax this rule in this specific case, but - // we'll still need to enforce it in C++03 mode. See N2253 (or - // successor). + // C++0x does relax this rule (see 5.1.1.10) in the first case, but we need to enforce it in C++03 mode. class Inner { static char a[sizeof(x)]; // expected-error {{ invalid use of nonstatic data member 'x' }} static char b[sizeof(sx)]; // okay + static char c[sizeof(f)]; // expected-error {{ call to non-static member function without an object argument }} }; }; diff --git a/test/CXX/class/class.union/p1.cpp b/test/CXX/class/class.union/p1.cpp index e974d82..b5dd4df 100644 --- a/test/CXX/class/class.union/p1.cpp +++ b/test/CXX/class/class.union/p1.cpp @@ -90,6 +90,14 @@ union U3 { } m7; }; +union U4 { + static int i1; // expected-error {{static data member 'i1' not allowed in union}} +}; + +union U5 { + int& i1; // expected-error {{union member 'i1' has reference type 'int &'}} +}; + template <class A, class B> struct Either { bool tag; union { diff --git a/test/CXX/class/p1-0x.cpp b/test/CXX/class/p1-0x.cpp new file mode 100644 index 0000000..5851de6 --- /dev/null +++ b/test/CXX/class/p1-0x.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x +namespace Test1 { + +class A final { }; +class B explicit { }; +class C final explicit { }; +class D final final { }; // expected-error {{class already marked 'final'}} +class E explicit explicit { }; // expected-error {{class already marked 'explicit'}} + +} diff --git a/test/CXX/class/p2-0x.cpp b/test/CXX/class/p2-0x.cpp new file mode 100644 index 0000000..630aa7e --- /dev/null +++ b/test/CXX/class/p2-0x.cpp @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x +namespace Test1 { + +class A final { }; // expected-note {{'A' declared here}} +class B : A { }; // expected-error {{base 'A' is marked 'final'}} + +} + +namespace Test2 { + +template<typename T> struct A final { }; // expected-note 2 {{'A' declared here}} +struct B : A<int> { }; // expected-error {{base 'A' is marked 'final'}} + +template<typename T> struct C : A<T> { }; // expected-error {{base 'A' is marked 'final'}} +struct D : C<int> { }; // expected-note {{in instantiation of template class 'Test2::C<int>' requested here}} + +} + +namespace Test3 { + +template<typename T> struct A { }; +template<> struct A<int> final { }; // expected-note {{'A' declared here}} + +struct B : A<bool> { }; +struct C : A<int> { }; // expected-error {{base 'A' is marked 'final'}} + +} + |