diff options
Diffstat (limited to 'test/CXX/class/class.mem')
-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 |
6 files changed, 201 insertions, 0 deletions
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'}} + }; +} |