summaryrefslogtreecommitdiff
path: root/clang/test/CXX/class
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-10-15 17:10:06 +1100
committerCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-10-15 17:10:06 +1100
commitbe1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch)
tree1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/test/CXX/class
parentc4626a62754862d20b41e8a46a3574264ea80e6d (diff)
parentf1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff)
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/CXX/class')
-rw-r--r--clang/test/CXX/class/class.base/class.base.init/p5-0x.cpp26
-rw-r--r--clang/test/CXX/class/class.bit/p2.cpp22
-rw-r--r--clang/test/CXX/class/class.friend/p1-ambiguous.cpp37
-rw-r--r--clang/test/CXX/class/class.friend/p1-cxx11.cpp12
-rw-r--r--clang/test/CXX/class/class.friend/p1.cpp77
-rw-r--r--clang/test/CXX/class/class.friend/p2.cpp10
-rw-r--r--clang/test/CXX/class/class.friend/p6.cpp10
-rw-r--r--clang/test/CXX/class/class.local/p1-0x.cpp18
-rw-r--r--clang/test/CXX/class/class.local/p1.cpp18
-rw-r--r--clang/test/CXX/class/class.local/p2.cpp11
-rw-r--r--clang/test/CXX/class/class.local/p3.cpp30
-rw-r--r--clang/test/CXX/class/class.local/p4.cpp10
-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
-rw-r--r--clang/test/CXX/class/class.mfct/class.mfct.non-static/p3.cpp98
-rw-r--r--clang/test/CXX/class/class.nest/p1-cxx0x.cpp14
-rw-r--r--clang/test/CXX/class/class.nest/p1.cpp14
-rw-r--r--clang/test/CXX/class/class.nest/p3.cpp25
-rw-r--r--clang/test/CXX/class/class.nested.type/p1.cpp13
-rw-r--r--clang/test/CXX/class/class.static/class.static.data/p3.cpp44
-rw-r--r--clang/test/CXX/class/class.static/class.static.data/p4.cpp25
-rw-r--r--clang/test/CXX/class/class.union/p1.cpp125
-rw-r--r--clang/test/CXX/class/class.union/p2-0x.cpp48
-rw-r--r--clang/test/CXX/class/p1-0x.cpp6
-rw-r--r--clang/test/CXX/class/p2-0x.cpp28
-rw-r--r--clang/test/CXX/class/p6-0x.cpp30
31 files changed, 1067 insertions, 0 deletions
diff --git a/clang/test/CXX/class/class.base/class.base.init/p5-0x.cpp b/clang/test/CXX/class/class.base/class.base.init/p5-0x.cpp
new file mode 100644
index 0000000..e9aa6da
--- /dev/null
+++ b/clang/test/CXX/class/class.base/class.base.init/p5-0x.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+// [class.base.init]p5
+// A ctor-initializer may initialize a variant member of the constructor’s
+// class. If a ctor-initializer specifies more than one mem-initializer for the
+// same member or for the same base class, the ctor-initializer is ill-formed.
+
+union E {
+ int a;
+ int b;
+ E() : a(1), // expected-note{{previous initialization is here}}
+ b(2) { // expected-error{{initializing multiple members of union}}
+ }
+};
+
+union F {
+ struct {
+ int a;
+ int b;
+ };
+ int c;
+ F() : a(1), // expected-note{{previous initialization is here}}
+ b(2),
+ c(3) { // expected-error{{initializing multiple members of union}}
+ }
+};
diff --git a/clang/test/CXX/class/class.bit/p2.cpp b/clang/test/CXX/class/class.bit/p2.cpp
new file mode 100644
index 0000000..7962330
--- /dev/null
+++ b/clang/test/CXX/class/class.bit/p2.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+struct A {
+private:
+ int : 0;
+};
+
+A a = { };
+A a2 = { 1 }; // expected-error{{excess elements in struct initializer}}
+
+struct B {
+ const int : 0;
+};
+
+B b;
+
+void testB() {
+ B b2(b);
+ B b3(static_cast<B&&>(b2));
+ b = b;
+ b = static_cast<B&&>(b);
+}
diff --git a/clang/test/CXX/class/class.friend/p1-ambiguous.cpp b/clang/test/CXX/class/class.friend/p1-ambiguous.cpp
new file mode 100644
index 0000000..a9dca4f
--- /dev/null
+++ b/clang/test/CXX/class/class.friend/p1-ambiguous.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Make sure that friend declarations don't introduce ambiguous
+// declarations.
+
+// Test case courtesy of Shantonu Sen.
+// Bug 4784.
+
+class foo;
+
+extern "C" {
+ int c_func(foo *a);
+};
+int cpp_func(foo *a);
+
+class foo {
+public:
+ friend int c_func(foo *a);
+ friend int cpp_func(foo *a);
+ int caller();
+private:
+ int x;
+};
+
+int c_func(foo *a) {
+ return a->x;
+}
+
+int cpp_func(foo *a) {
+ return a->x;
+}
+
+int foo::caller() {
+ c_func(this);
+ cpp_func(this);
+ return 0;
+}
diff --git a/clang/test/CXX/class/class.friend/p1-cxx11.cpp b/clang/test/CXX/class/class.friend/p1-cxx11.cpp
new file mode 100644
index 0000000..235f295
--- /dev/null
+++ b/clang/test/CXX/class/class.friend/p1-cxx11.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+class A {
+ class AInner {
+ };
+
+ void a_member();
+ friend void A::a_member(); // ok in c++11, ill-formed in c++98
+ friend void a_member(); // ok in both, refers to non-member
+ friend class A::AInner; // ok in c++11, extension in c++98
+ friend class AInner; // ok in both, refers to non-member
+};
diff --git a/clang/test/CXX/class/class.friend/p1.cpp b/clang/test/CXX/class/class.friend/p1.cpp
new file mode 100644
index 0000000..07b3a10
--- /dev/null
+++ b/clang/test/CXX/class/class.friend/p1.cpp
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct Outer {
+ struct Inner {
+ int intfield;
+ };
+};
+
+struct Base {
+ void base_member();
+
+ typedef int Int;
+ Int typedeffed_member();
+};
+
+struct Derived : public Base {
+};
+
+int myglobal;
+
+void global_function();
+extern "C" {
+ void global_c_function();
+}
+
+class A {
+ class AInner {
+ };
+
+ friend class PreDeclared;
+ friend class Outer::Inner;
+ friend int Outer::Inner::intfield; // expected-error {{friends can only be classes or functions}}
+ friend int Outer::Inner::missing_field; //expected-error {{friends can only be classes or functions}}
+ friend int myoperation(float); // okay
+ friend int myglobal; // expected-error {{friends can only be classes or functions}}
+
+ friend void global_function();
+ friend void global_c_function();
+
+ friend class UndeclaredSoFar;
+ UndeclaredSoFar x; // expected-error {{unknown type name 'UndeclaredSoFar'}}
+
+ void a_member();
+ friend void A::a_member(); // expected-error {{friends cannot be members of the declaring class}}
+ friend void a_member(); // okay (because we ignore class scopes when looking up friends)
+ friend class A::AInner; // this is okay as an extension
+ friend class AInner; // okay, refers to ::AInner
+
+ friend void Derived::missing_member(); // expected-error {{no function named 'missing_member' with type 'void ()' was found in the specified scope}}
+
+ friend void Derived::base_member(); // expected-error {{no function named 'base_member' with type 'void ()' was found in the specified scope}}
+
+ friend int Base::typedeffed_member(); // okay: should look through typedef
+
+ // These test that the friend is properly not being treated as a
+ // member function.
+ 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}} \
+ // expected-error{{non-member function cannot have 'const' qualifier}}
+
+ typedef void ftypedef();
+ friend ftypedef typedeffed_function; // okay (because it's not declared as a member)
+
+ class facet;
+ friend class facet; // should not assert
+ class facet {};
+};
+
+A::UndeclaredSoFar y; // expected-error {{no type named 'UndeclaredSoFar' in 'A'}}
+
+class PreDeclared;
+
+int myoperation(float f) {
+ return (int) f;
+}
diff --git a/clang/test/CXX/class/class.friend/p2.cpp b/clang/test/CXX/class/class.friend/p2.cpp
new file mode 100644
index 0000000..fb3cd19
--- /dev/null
+++ b/clang/test/CXX/class/class.friend/p2.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct B0;
+
+class A {
+ friend class B {}; // expected-error {{cannot define a type in a friend declaration}}
+ friend int; // expected-warning {{non-class friend type 'int' is a C++11 extension}}
+ friend B0; // expected-warning {{specify 'struct' to befriend 'B0'}}
+ friend class C; // okay
+};
diff --git a/clang/test/CXX/class/class.friend/p6.cpp b/clang/test/CXX/class/class.friend/p6.cpp
new file mode 100644
index 0000000..7d7a064
--- /dev/null
+++ b/clang/test/CXX/class/class.friend/p6.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -Wc++11-compat -verify %s
+
+class A {
+ friend static class B; // expected-error {{'static' is invalid in friend declarations}}
+ friend extern class C; // expected-error {{'extern' is invalid in friend declarations}}
+ friend auto class D; // expected-warning {{incompatible with C++11}} expected-error {{'auto' is invalid in friend declarations}}
+ friend register class E; // expected-error {{'register' is invalid in friend declarations}}
+ friend mutable class F; // expected-error {{'mutable' is invalid in friend declarations}}
+ friend typedef class G; // expected-error {{'typedef' is invalid in friend declarations}}
+};
diff --git a/clang/test/CXX/class/class.local/p1-0x.cpp b/clang/test/CXX/class/class.local/p1-0x.cpp
new file mode 100644
index 0000000..49125f5
--- /dev/null
+++ b/clang/test/CXX/class/class.local/p1-0x.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+void f() {
+ int x = 3; // expected-note{{'x' declared here}}
+ const int c = 2;
+ struct C {
+ int& x2 = x; // expected-error{{reference to local variable 'x' declared in enclosing function 'f'}}
+ int cc = c;
+ };
+ (void)[]() mutable {
+ int x = 3; // expected-note{{'x' declared here}}
+ struct C {
+ int& x2 = x; // expected-error{{reference to local variable 'x' declared in enclosing lambda expression}}
+ };
+ };
+ C();
+}
+
diff --git a/clang/test/CXX/class/class.local/p1.cpp b/clang/test/CXX/class/class.local/p1.cpp
new file mode 100644
index 0000000..62ade5c
--- /dev/null
+++ b/clang/test/CXX/class/class.local/p1.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int x;
+void f()
+{
+ static int s;
+ int x; // expected-note{{'x' declared here}}
+ extern int g();
+
+ struct local {
+ int g() { return x; } // expected-error{{reference to local variable 'x' declared in enclosing function 'f'}}
+ int h() { return s; }
+ int k() { return :: x; }
+ int l() { return g(); }
+ };
+}
+
+local* p = 0; // expected-error{{unknown type name 'local'}}
diff --git a/clang/test/CXX/class/class.local/p2.cpp b/clang/test/CXX/class/class.local/p2.cpp
new file mode 100644
index 0000000..db4c90f
--- /dev/null
+++ b/clang/test/CXX/class/class.local/p2.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct A { };
+
+void f() {
+ struct B : private A {}; // expected-note{{declared private here}}
+
+ B b;
+
+ A *a = &b; // expected-error{{cannot cast 'B' to its private base class 'A'}}
+}
diff --git a/clang/test/CXX/class/class.local/p3.cpp b/clang/test/CXX/class/class.local/p3.cpp
new file mode 100644
index 0000000..3753790
--- /dev/null
+++ b/clang/test/CXX/class/class.local/p3.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void f1() {
+ struct X {
+ struct Y;
+ };
+
+ struct X::Y {
+ void f() {}
+ };
+}
+
+void f2() {
+ struct X {
+ struct Y;
+
+ struct Y {
+ void f() {}
+ };
+ };
+}
+
+// A class nested within a local class is a local class.
+void f3(int a) { // expected-note{{'a' declared here}}
+ struct X {
+ struct Y {
+ int f() { return a; } // expected-error{{reference to local variable 'a' declared in enclosing function 'f3'}}
+ };
+ };
+}
diff --git a/clang/test/CXX/class/class.local/p4.cpp b/clang/test/CXX/class/class.local/p4.cpp
new file mode 100644
index 0000000..d780744
--- /dev/null
+++ b/clang/test/CXX/class/class.local/p4.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void f() {
+ struct X {
+ static int a; // expected-error {{static data member 'a' not allowed in local class 'X'}}
+ int b;
+
+ static void f() { }
+ };
+}
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'}}
+ };
+}
diff --git a/clang/test/CXX/class/class.mfct/class.mfct.non-static/p3.cpp b/clang/test/CXX/class/class.mfct/class.mfct.non-static/p3.cpp
new file mode 100644
index 0000000..9116e71
--- /dev/null
+++ b/clang/test/CXX/class/class.mfct/class.mfct.non-static/p3.cpp
@@ -0,0 +1,98 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// [class.mfct.non-static]p3:
+// When an id-expression (5.1) that is not part of a class member
+// access syntax (5.2.5) and not used to form a pointer to member
+// (5.3.1) is used in the body of a non-static member function of
+// class X, if name lookup (3.4.1) resolves the name in the
+// id-expression to a non-static non-type member of some class C,
+// the id-expression is transformed into a class member access
+// expression (5.2.5) using (*this) (9.3.2) as the
+// postfix-expression to the left of the . operator. [ Note: if C is
+// not X or a base class of X, the class member access expression is
+// ill-formed. --end note] Similarly during name lookup, when an
+// unqualified-id (5.1) used in the definition of a member function
+// for class X resolves to a static member, an enumerator or a
+// nested type of class X or of a base class of X, the
+// unqualified-id is transformed into a qualified-id (5.1) in which
+// the nested-name-specifier names the class of the member function.
+
+namespace test0 {
+ class A {
+ int data_member;
+ int instance_method();
+ static int static_method();
+
+ bool test() {
+ return data_member + instance_method() < static_method();
+ }
+ };
+}
+
+namespace test1 {
+ struct Opaque1 {}; struct Opaque2 {}; struct Opaque3 {};
+
+ struct A {
+ void foo(Opaque1); // expected-note {{candidate}}
+ void foo(Opaque2); // expected-note {{candidate}}
+ };
+
+ struct B : A {
+ void test();
+ };
+
+ struct C1 : A { };
+ struct C2 : B { };
+
+ void B::test() {
+ A::foo(Opaque1());
+ A::foo(Opaque2());
+ A::foo(Opaque3()); // expected-error {{no matching member function}}
+
+ C1::foo(Opaque1()); // expected-error {{call to non-static member function without an object argument}}
+ C2::foo(Opaque1()); // expected-error {{call to non-static member function without an object argument}}
+ }
+}
+
+namespace test2 {
+ struct Unrelated {
+ void foo();
+ };
+
+ template <class T> struct B;
+ template <class T> struct C;
+
+ template <class T> struct A {
+ void foo();
+
+ void test0() {
+ Unrelated::foo(); // expected-error {{call to non-static member function without an object argument}}
+ }
+
+ void test1() {
+ B<T>::foo();
+ }
+
+ static void test2() {
+ B<T>::foo(); // expected-error {{call to non-static member function without an object argument}}
+ }
+
+ void test3() {
+ C<T>::foo(); // expected-error {{no member named 'foo'}}
+ }
+ };
+
+ template <class T> struct B : A<T> {
+ };
+
+ template <class T> struct C {
+ };
+
+ int test() {
+ A<int> a;
+ a.test0(); // no instantiation note here, decl is ill-formed
+ a.test1();
+ a.test2(); // expected-note {{in instantiation}}
+ a.test3(); // expected-note {{in instantiation}}
+ }
+}
diff --git a/clang/test/CXX/class/class.nest/p1-cxx0x.cpp b/clang/test/CXX/class/class.nest/p1-cxx0x.cpp
new file mode 100644
index 0000000..b7a1a48
--- /dev/null
+++ b/clang/test/CXX/class/class.nest/p1-cxx0x.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -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/clang/test/CXX/class/class.nest/p1.cpp b/clang/test/CXX/class/class.nest/p1.cpp
new file mode 100644
index 0000000..b0341da
--- /dev/null
+++ b/clang/test/CXX/class/class.nest/p1.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+class Outer {
+ int x;
+ static int sx;
+ int f();
+
+ // C++11 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 non-static 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/clang/test/CXX/class/class.nest/p3.cpp b/clang/test/CXX/class/class.nest/p3.cpp
new file mode 100644
index 0000000..c4c4ca7
--- /dev/null
+++ b/clang/test/CXX/class/class.nest/p3.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// C++0x [class.nest] p3:
+// If class X is defined in a namespace scope, a nested class Y may be
+// declared in class X and later defined in the definition of class X or be
+// later defined in a namespace scope enclosing the definition of class X.
+
+namespace example {
+ class E {
+ class I1;
+ class I2;
+ class I1 { };
+ };
+ class E::I2 { };
+}
+
+// Don't insert out-of-line inner class definitions into the namespace scope.
+namespace PR6107 {
+ struct S1 { };
+ struct S2 {
+ struct S1;
+ };
+ struct S2::S1 { };
+ S1 s1;
+}
diff --git a/clang/test/CXX/class/class.nested.type/p1.cpp b/clang/test/CXX/class/class.nested.type/p1.cpp
new file mode 100644
index 0000000..4a04a44
--- /dev/null
+++ b/clang/test/CXX/class/class.nested.type/p1.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+class X {
+public:
+ typedef int I;
+ class Y { };
+ I a;
+};
+
+I b; // expected-error{{unknown type name 'I'}}
+Y c; // expected-error{{unknown type name 'Y'}}
+X::Y d;
+X::I e;
diff --git a/clang/test/CXX/class/class.static/class.static.data/p3.cpp b/clang/test/CXX/class/class.static/class.static.data/p3.cpp
new file mode 100644
index 0000000..117997e
--- /dev/null
+++ b/clang/test/CXX/class/class.static/class.static.data/p3.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+struct NonLit { // expected-note 3{{no constexpr constructors}}
+ NonLit();
+};
+
+struct S {
+ static constexpr int a = 0;
+ static constexpr int b; // expected-error {{declaration of constexpr static data member 'b' requires an initializer}}
+
+ static constexpr int c = 0;
+ static const int d;
+ static const int d2 = 0;
+
+ static constexpr double e = 0.0; // ok
+ static const double f = 0.0; // expected-warning {{extension}} expected-note {{use 'constexpr' specifier}}
+ static char *const g = 0; // expected-error {{requires 'constexpr' specifier}}
+ static const NonLit h = NonLit(); // expected-error {{must be initialized out of line}}
+};
+
+constexpr int S::a;
+constexpr int S::b = 0;
+
+const int S::c;
+constexpr int S::d = 0;
+constexpr int S::d2;
+
+template<typename T>
+struct U {
+ static constexpr int a = 0;
+ static constexpr int b; // expected-error {{declaration of constexpr static data member 'b' requires an initializer}}
+ static constexpr NonLit h = NonLit(); // expected-error {{cannot have non-literal type 'const NonLit'}}
+ static constexpr T c = T(); // expected-error {{cannot have non-literal type}}
+ static const T d;
+};
+
+template<typename T> constexpr T U<T>::d = T(); // expected-error {{non-literal type 'const NonLit'}}
+
+U<int> u1;
+U<NonLit> u2; // expected-note {{here}}
+
+static_assert(U<int>::a == 0, "");
+
+constexpr int outofline = (U<NonLit>::d, 0); // expected-note {{here}} expected-warning {{unused}}
diff --git a/clang/test/CXX/class/class.static/class.static.data/p4.cpp b/clang/test/CXX/class/class.static/class.static.data/p4.cpp
new file mode 100644
index 0000000..2b1eca7
--- /dev/null
+++ b/clang/test/CXX/class/class.static/class.static.data/p4.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+struct InClassInitializerOnly {
+ static const int i = 0;
+};
+int const InClassInitializerOnly::i;
+
+struct OutOfClassInitializerOnly {
+ static const int i;
+};
+int const OutOfClassInitializerOnly::i = 0;
+
+struct InClassInitializerAndOutOfClassCopyInitializer {
+ static const int i = 0; // expected-note{{previous definition is here}}
+};
+int const InClassInitializerAndOutOfClassCopyInitializer::i = 0; // expected-error{{redefinition of 'i'}}
+
+struct InClassInitializerAndOutOfClassDirectInitializer {
+ static const int i = 0; // expected-note{{previous definition is here}}
+};
+int const InClassInitializerAndOutOfClassDirectInitializer::i(0); // expected-error{{redefinition of 'i'}}
+
+
+
+int main() { }
+
diff --git a/clang/test/CXX/class/class.union/p1.cpp b/clang/test/CXX/class/class.union/p1.cpp
new file mode 100644
index 0000000..f344ae5
--- /dev/null
+++ b/clang/test/CXX/class/class.union/p1.cpp
@@ -0,0 +1,125 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void abort() __attribute__((noreturn));
+
+class Okay {
+ int a_;
+};
+
+class Virtual {
+ virtual void foo() { abort(); } // expected-note 4 {{because type 'Virtual' has a virtual member function}}
+};
+
+class VirtualBase : virtual Okay { // expected-note 4 {{because type 'VirtualBase' has a virtual base class}}
+};
+
+class Ctor {
+ Ctor() { abort(); } // expected-note 4 {{because type 'Ctor' has a user-declared constructor}}
+};
+class Ctor2 {
+ Ctor2(); // expected-note 3 {{because type 'Ctor2' has a user-declared constructor}}
+};
+class CtorTmpl {
+ template<typename T> CtorTmpl(); // expected-note {{because type 'CtorTmpl' has a user-declared constructor}}
+};
+
+class CopyCtor {
+ CopyCtor(CopyCtor &cc) { abort(); } // expected-note 4 {{because type 'CopyCtor' has a user-declared copy constructor}}
+};
+
+// FIXME: this should eventually trigger on the operator's declaration line
+class CopyAssign { // expected-note 4 {{because type 'CopyAssign' has a user-declared copy assignment operator}}
+ CopyAssign& operator=(CopyAssign& CA) { abort(); }
+};
+
+class Dtor {
+ ~Dtor() { abort(); } // expected-note 4 {{because type 'Dtor' has a user-declared destructor}}
+};
+
+union U1 {
+ Virtual v; // expected-error {{union member 'v' has a non-trivial copy constructor}}
+ VirtualBase vbase; // expected-error {{union member 'vbase' has a non-trivial copy constructor}}
+ Ctor ctor; // expected-error {{union member 'ctor' has a non-trivial constructor}}
+ Ctor2 ctor2; // expected-error {{union member 'ctor2' has a non-trivial constructor}}
+ CtorTmpl ctortmpl; // expected-error {{union member 'ctortmpl' has a non-trivial constructor}}
+ CopyCtor copyctor; // expected-error {{union member 'copyctor' has a non-trivial copy constructor}}
+ CopyAssign copyassign; // expected-error {{union member 'copyassign' has a non-trivial copy assignment operator}}
+ Dtor dtor; // expected-error {{union member 'dtor' has a non-trivial destructor}}
+ Okay okay;
+};
+
+union U2 {
+ struct {
+ Virtual v; // expected-note {{because type 'U2::<anonymous struct}}
+ } m1; // expected-error {{union member 'm1' has a non-trivial copy constructor}}
+ struct {
+ VirtualBase vbase; // expected-note {{because type 'U2::<anonymous struct}}
+ } m2; // expected-error {{union member 'm2' has a non-trivial copy constructor}}
+ struct {
+ Ctor ctor; // expected-note {{because type 'U2::<anonymous struct}}
+ } m3; // expected-error {{union member 'm3' has a non-trivial constructor}}
+ struct {
+ Ctor2 ctor2; // expected-note {{because type 'U2::<anonymous struct}}
+ } m3a; // expected-error {{union member 'm3a' has a non-trivial constructor}}
+ struct {
+ CopyCtor copyctor; // expected-note {{because type 'U2::<anonymous struct}}
+ } m4; // expected-error {{union member 'm4' has a non-trivial copy constructor}}
+ struct {
+ CopyAssign copyassign; // expected-note {{because type 'U2::<anonymous struct}}
+ } m5; // expected-error {{union member 'm5' has a non-trivial copy assignment operator}}
+ struct {
+ Dtor dtor; // expected-note {{because type 'U2::<anonymous struct}}
+ } m6; // expected-error {{union member 'm6' has a non-trivial destructor}}
+ struct {
+ Okay okay;
+ } m7;
+};
+
+union U3 {
+ struct s1 : Virtual { // expected-note {{because type 'U3::s1' has a base class with a non-trivial copy constructor}}
+ } m1; // expected-error {{union member 'm1' has a non-trivial copy constructor}}
+ struct s2 : VirtualBase { // expected-note {{because type 'U3::s2' has a base class with a non-trivial copy constructor}}
+ } m2; // expected-error {{union member 'm2' has a non-trivial copy constructor}}
+ struct s3 : Ctor { // expected-note {{because type 'U3::s3' has a base class with a non-trivial constructor}}
+ } m3; // expected-error {{union member 'm3' has a non-trivial constructor}}
+ struct s3a : Ctor2 { // expected-note {{because type 'U3::s3a' has a base class with a non-trivial constructor}}
+ } m3a; // expected-error {{union member 'm3a' has a non-trivial constructor}}
+ struct s4 : CopyCtor { // expected-note {{because type 'U3::s4' has a base class with a non-trivial copy constructor}}
+ } m4; // expected-error {{union member 'm4' has a non-trivial copy constructor}}
+ struct s5 : CopyAssign { // expected-note {{because type 'U3::s5' has a base class with a non-trivial copy assignment operator}}
+ } m5; // expected-error {{union member 'm5' has a non-trivial copy assignment operator}}
+ struct s6 : Dtor { // expected-note {{because type 'U3::s6' has a base class with a non-trivial destructor}}
+ } m6; // expected-error {{union member 'm6' has a non-trivial destructor}}
+ struct s7 : Okay {
+ } m7;
+};
+
+union U4 {
+ static int i1; // expected-warning {{static data member 'i1' in union is a C++11 extension}}
+};
+int U4::i1 = 10;
+
+union U5 {
+ int& i1; // expected-error {{union member 'i1' has reference type 'int &'}}
+};
+
+template <class A, class B> struct Either {
+ bool tag;
+ union { // expected-note 6 {{in instantiation of member class}}
+ A a;
+ B b; // expected-error 6 {{non-trivial}}
+ };
+
+ Either(const A& a) : tag(true), a(a) {}
+ Either(const B& b) : tag(false), b(b) {}
+};
+
+void fred() {
+ Either<int,Virtual> virt(0); // expected-note {{in instantiation of template}}
+ Either<int,VirtualBase> vbase(0); // expected-note {{in instantiation of template}}
+ Either<int,Ctor> ctor(0); // expected-note {{in instantiation of template}}
+ Either<int,CopyCtor> copyctor(0); // expected-note {{in instantiation of template}}
+ Either<int,CopyAssign> copyassign(0); // expected-note {{in instantiation of template}}
+ Either<int,Dtor> dtor(0); // expected-note {{in instantiation of template}}
+ Either<int,Okay> okay(0);
+}
diff --git a/clang/test/CXX/class/class.union/p2-0x.cpp b/clang/test/CXX/class/class.union/p2-0x.cpp
new file mode 100644
index 0000000..b5c4109
--- /dev/null
+++ b/clang/test/CXX/class/class.union/p2-0x.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -verify -std=c++11 %s
+
+// Unlike in C++98, C++11 allows unions to have static data members.
+
+union U1 {
+ static constexpr int k1 = 0;
+ static const int k2 = k1;
+ static int k3 = k2; // expected-error {{non-const static data member must be initialized out of line}}
+ static constexpr double k4 = k2;
+ static const double k5 = k4; // expected-warning {{GNU extension}} expected-note {{use 'constexpr'}}
+ int n[k1 + 3];
+};
+
+constexpr int U1::k1;
+constexpr int U1::k2;
+int U1::k3;
+
+const double U1::k4;
+const double U1::k5;
+
+template<typename T>
+union U2 {
+ static const int k1;
+ static double k2;
+ T t;
+};
+template<typename T> constexpr int U2<T>::k1 = sizeof(U2<T>);
+template<typename T> double U2<T>::k2 = 5.3;
+
+static_assert(U2<int>::k1 == sizeof(int), "");
+static_assert(U2<char>::k1 == sizeof(char), "");
+
+union U3 {
+ static const int k;
+ U3() : k(0) {} // expected-error {{does not name a non-static data member}}
+};
+
+struct S {
+ union {
+ static const int n; // expected-error {{static members cannot be declared in an anonymous union}}
+ int a;
+ int b;
+ };
+};
+static union {
+ static const int k; // expected-error {{static members cannot be declared in an anonymous union}}
+ int n;
+};
diff --git a/clang/test/CXX/class/p1-0x.cpp b/clang/test/CXX/class/p1-0x.cpp
new file mode 100644
index 0000000..be5fdff
--- /dev/null
+++ b/clang/test/CXX/class/p1-0x.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+namespace Test1 {
+
+class A final { };
+
+}
diff --git a/clang/test/CXX/class/p2-0x.cpp b/clang/test/CXX/class/p2-0x.cpp
new file mode 100644
index 0000000..dbb01e5
--- /dev/null
+++ b/clang/test/CXX/class/p2-0x.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+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'}}
+
+}
+
diff --git a/clang/test/CXX/class/p6-0x.cpp b/clang/test/CXX/class/p6-0x.cpp
new file mode 100644
index 0000000..f2cf482
--- /dev/null
+++ b/clang/test/CXX/class/p6-0x.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+
+class Trivial { int n; void f(); };
+class NonTrivial1 { NonTrivial1(const NonTrivial1 &); };
+class NonTrivial2 { NonTrivial2(NonTrivial2 &&); };
+class NonTrivial3 { NonTrivial3 operator=(const NonTrivial3 &); };
+class NonTrivial4 { NonTrivial4 operator=(NonTrivial4 &&); };
+class NonTrivial5 { ~NonTrivial5(); };
+
+static_assert(__is_trivial(Trivial), "Trivial is not trivial");
+static_assert(!__is_trivial(NonTrivial1), "NonTrivial1 is trivial");
+static_assert(!__is_trivial(NonTrivial2), "NonTrivial2 is trivial");
+static_assert(!__is_trivial(NonTrivial3), "NonTrivial3 is trivial");
+static_assert(!__is_trivial(NonTrivial4), "NonTrivial4 is trivial");
+static_assert(!__is_trivial(NonTrivial5), "NonTrivial5 is trivial");
+
+struct Trivial2 {
+ Trivial2() = default;
+ Trivial2(const Trivial2 &) = default;
+ Trivial2(Trivial2 &&) = default;
+ Trivial2 &operator=(const Trivial2 &) = default;
+ Trivial2 &operator=(Trivial2 &) = default;
+ ~Trivial2() = default;
+};
+
+class NonTrivial6 { ~NonTrivial6(); };
+
+NonTrivial6::~NonTrivial6() = default;
+
+static_assert(!__is_trivial(NonTrivial6), "NonTrivial6 is trivial");