summaryrefslogtreecommitdiff
path: root/clang/test/CXX/class/class.mem
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/CXX/class/class.mem')
-rw-r--r--clang/test/CXX/class/class.mem/p1.cpp91
-rw-r--r--clang/test/CXX/class/class.mem/p13.cpp40
-rw-r--r--clang/test/CXX/class/class.mem/p14.cpp19
-rw-r--r--clang/test/CXX/class/class.mem/p1b.cpp46
-rw-r--r--clang/test/CXX/class/class.mem/p2.cpp58
-rw-r--r--clang/test/CXX/class/class.mem/p5-0x.cpp9
-rw-r--r--clang/test/CXX/class/class.mem/p8-0x.cpp53
7 files changed, 316 insertions, 0 deletions
diff --git a/clang/test/CXX/class/class.mem/p1.cpp b/clang/test/CXX/class/class.mem/p1.cpp
new file mode 100644
index 0000000..a41f1db
--- /dev/null
+++ b/clang/test/CXX/class/class.mem/p1.cpp
@@ -0,0 +1,91 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct S
+{
+ static int v1; // expected-note{{previous declaration is here}}
+ int v1; //expected-error{{duplicate member 'v1'}}
+ int v; //expected-note 2{{previous definition is here}} \
+ // expected-note{{previous declaration is here}}
+ static int v; //expected-error{{redefinition of 'v' as different kind of symbol}}
+ int v; //expected-error{{duplicate member 'v'}}
+ static int v; //expected-error{{redefinition of 'v' as different kind of symbol}}
+ enum EnumT { E = 10 };
+ friend struct M;
+ struct X; //expected-note{{forward declaration of 'S::X'}}
+ friend struct X;
+};
+
+S::EnumT Evar = S::E; // ok
+S::EnumT Evar2 = EnumT(); //expected-error{{use of undeclared identifier 'EnumT'}}
+S::M m; //expected-error{{no type named 'M' in 'S'}}
+S::X x; //expected-error{{variable has incomplete type 'S::X'}}
+
+
+struct S2
+{
+ static int v2; // expected-note{{previous declaration is here}}
+ static int v2; //expected-error{{duplicate member 'v2'}}
+};
+
+struct S3
+{
+ static int v3;
+ struct S4
+ {
+ static int v3;
+ };
+};
+
+struct S4
+{
+ static int v4;
+};
+
+int S4::v4; //expected-note{{previous definition is here}}
+int S4::v4; //expected-error{{redefinition of 'v4'}}
+
+struct S5
+{
+ static int v5; //expected-note{{previous definition is here}}
+ void v5() { } //expected-error{{redefinition of 'v5' as different kind of symbol}}
+
+ void v6() { } //expected-note{{previous definition is here}}
+ static int v6; //expected-error{{redefinition of 'v6' as different kind of symbol}}
+
+ void v7() { }
+ void v7(int) { } //expected-note{{previous definition is here}}
+ static int v7; //expected-error{{redefinition of 'v7' as different kind of symbol}}
+
+ void v8();
+ int v8(int); //expected-note{{previous declaration is here}}
+ int v8; //expected-error{{duplicate member 'v8'}}
+
+
+};
+
+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/clang/test/CXX/class/class.mem/p13.cpp b/clang/test/CXX/class/class.mem/p13.cpp
new file mode 100644
index 0000000..8488584
--- /dev/null
+++ b/clang/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/clang/test/CXX/class/class.mem/p14.cpp b/clang/test/CXX/class/class.mem/p14.cpp
new file mode 100644
index 0000000..72b232e
--- /dev/null
+++ b/clang/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/clang/test/CXX/class/class.mem/p1b.cpp b/clang/test/CXX/class/class.mem/p1b.cpp
new file mode 100644
index 0000000..3e8c985
--- /dev/null
+++ b/clang/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);
+
+ // CHECK: 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/clang/test/CXX/class/class.mem/p2.cpp b/clang/test/CXX/class/class.mem/p2.cpp
new file mode 100644
index 0000000..4aa4a5c
--- /dev/null
+++ b/clang/test/CXX/class/class.mem/p2.cpp
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+// C++11 [class.mem]p2:
+// A class is considered a completely-defined object type (or
+// complete type) at the closing } of the class-specifier. Within
+// the class member-specification, the class is regarded as complete
+// within function bodies, default arguments,
+// exception-specifications, and brace-or-equal-initializers for
+// non-static data members (including such things in nested classes).
+// Otherwise it is regarded as incomplete within its own class
+// member-specification.
+
+namespace test0 {
+ struct A { // expected-note {{definition of 'test0::A' is not complete until the closing '}'}}
+ A x; // expected-error {{field has incomplete type 'test0::A'}}
+ };
+}
+
+namespace test1 {
+ template <class T> struct A {
+ A<int> x; // expected-error {{implicit instantiation of template 'test1::A<int>' within its own definition}}
+ };
+}
+
+namespace test2 {
+ template <class T> struct A;
+ template <> struct A<int> {};
+ template <class T> struct A {
+ A<int> x;
+ };
+}
+
+namespace test3 {
+ struct A {
+ struct B {
+ void f() throw(A);
+ void g() throw(B);
+ };
+
+ void f() throw(A);
+ void g() throw(B);
+ };
+
+ template<typename T>
+ struct A2 {
+ struct B {
+ void f1() throw(A2);
+ void f2() throw(A2<T>);
+ void g() throw(B);
+ };
+
+ void f1() throw(A2);
+ void f2() throw(A2<T>);
+ void g() throw(B);
+ };
+
+ template struct A2<int>;
+}
diff --git a/clang/test/CXX/class/class.mem/p5-0x.cpp b/clang/test/CXX/class/class.mem/p5-0x.cpp
new file mode 100644
index 0000000..6061c4c
--- /dev/null
+++ b/clang/test/CXX/class/class.mem/p5-0x.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+int f();
+
+struct S
+{
+ int a = f(); // ok
+ int b = g(); // expected-error {{use of undeclared identifier 'g'}}
+};
diff --git a/clang/test/CXX/class/class.mem/p8-0x.cpp b/clang/test/CXX/class/class.mem/p8-0x.cpp
new file mode 100644
index 0000000..d2c3dc3
--- /dev/null
+++ b/clang/test/CXX/class/class.mem/p8-0x.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+
+struct Base1 {
+ virtual void g();
+};
+
+struct A : Base1 {
+ 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 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'}}
+ };
+}