From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp | 358 ++++++++++++++++++++++ clang/test/CXX/temp/temp.decls/temp.friend/p3.cpp | 12 + clang/test/CXX/temp/temp.decls/temp.friend/p4.cpp | 28 ++ clang/test/CXX/temp/temp.decls/temp.friend/p5.cpp | 103 +++++++ clang/test/CXX/temp/temp.decls/temp.friend/p8.cpp | 6 + 5 files changed, 507 insertions(+) create mode 100644 clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp create mode 100644 clang/test/CXX/temp/temp.decls/temp.friend/p3.cpp create mode 100644 clang/test/CXX/temp/temp.decls/temp.friend/p4.cpp create mode 100644 clang/test/CXX/temp/temp.decls/temp.friend/p5.cpp create mode 100644 clang/test/CXX/temp/temp.decls/temp.friend/p8.cpp (limited to 'clang/test/CXX/temp/temp.decls/temp.friend') diff --git a/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp b/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp new file mode 100644 index 0000000..63f569b --- /dev/null +++ b/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp @@ -0,0 +1,358 @@ +// RUN: %clang_cc1 -verify -emit-llvm-only %s + +namespace test0 { +template struct Num { + T value_; + +public: + Num(T value) : value_(value) {} + T get() const { return value_; } + + template struct Rep { + U count_; + Rep(U count) : count_(count) {} + + friend Num operator*(const Num &a, const Rep &n) { + Num x = 0; + for (U count = n.count_; count; --count) + x += a; + return x; + } + }; + + friend Num operator+(const Num &a, const Num &b) { + return a.value_ + b.value_; + } + + Num& operator+=(const Num& b) { + value_ += b.value_; + return *this; + } + + class Representation {}; + friend class Representation; +}; + +class A { + template friend bool iszero(const A &a) throw(); +}; + +template class B_iterator; +template class B { + friend class B_iterator; +}; + +int calc1() { + Num left = -1; + Num right = 1; + Num result = left + right; + return result.get(); +} + +int calc2() { + Num x = 3; + Num::Rep n = (char) 10; + Num result = x * n; + return result.get(); +} +} + +// Reduced from GNU +namespace test1 { + class A { + bool b; // expected-note {{declared private here}} + template friend bool has(const A&); + }; + template bool has(const A &x) { + return x.b; + } + template bool hasnot(const A &x) { + return x.b; // expected-error {{'b' is a private member of 'test1::A'}} + } +} + +namespace test2 { + class A { + bool b; // expected-note {{declared private here}} + template friend class HasChecker; + }; + template class HasChecker { + bool check(A *a) { + return a->b; + } + }; + template class HasNotChecker { + bool check(A *a) { + return a->b; // expected-error {{'b' is a private member of 'test2::A'}} + } + }; +} + +namespace test3 { + class Bool; + template class User; + template T transform(class Bool, T); + + class Bool { + friend class User; + friend bool transform<>(Bool, bool); + + bool value; // expected-note 2 {{declared private here}} + }; + + template class User { + static T compute(Bool b) { + return b.value; // expected-error {{'value' is a private member of 'test3::Bool'}} + } + }; + + template T transform(Bool b, T value) { + if (b.value) // expected-error {{'value' is a private member of 'test3::Bool'}} + return value; + return value + 1; + } + + template bool transform(Bool, bool); + template int transform(Bool, int); // expected-note {{requested here}} + + template class User; + template class User; // expected-note {{requested here}} +} + +namespace test4 { + template class A { + template friend class B; + bool foo(const A *) const; + }; + + template class B { + bool bar(const A *a, const A *b) { + return a->foo(b); + } + }; + + template class B; +} + +namespace test5 { + template class A {}; + template class B { + template friend class A; + }; + template class B; + template class A; +} + +namespace Dependent { + template class X; + template + X operator+(const X&, const T*); + + template class X { + typedef typename Traits::value_type value_type; + friend X operator+<>(const X&, const value_type*); + }; +} + +namespace test7 { + template class A { // expected-note {{declared here}} + friend class B; + int x; // expected-note {{declared private here}} + }; + + class B { + int foo(A &a) { + return a.x; + } + }; + + class C { + int foo(A &a) { + return a.x; // expected-error {{'x' is a private member of 'test7::A'}} + } + }; + + // This shouldn't crash. + template class D { + friend class A; // expected-error {{elaborated type refers to a template}} + }; + template class D; +} + +namespace test8 { + template class A { + static int x; + template friend void foo(); + }; + template class A; + + template void foo() { + A::x = 0; + } + template void foo(); +} + +namespace test9 { + template class A { + class B; class C; + + int foo(B *b) { + return b->x; + } + + int foo(C *c) { + return c->x; // expected-error {{'x' is a private member}} + } + + class B { + int x; + friend int A::foo(B*); + }; + + class C { + int x; // expected-note {{declared private here}} + }; + }; + + template class A; // expected-note {{in instantiation}} +} + +namespace test10 { + template class A; + template A bar(const T*, const A&); + template class A { + private: + void foo(); // expected-note {{declared private here}} + friend A bar<>(const T*, const A&); + }; + + template A bar(const T *l, const A &r) { + A l1; + l1.foo(); + + A l2; + l2.foo(); // expected-error {{'foo' is a private member of 'test10::A'}} + + return l1; + } + + template A bar(const int *, const A &); // expected-note {{in instantiation}} +} + +// PR6752: this shouldn't crash. +namespace test11 { + struct Foo { + template + struct IteratorImpl { + template friend class IteratorImpl; + }; + }; + + template struct Foo::IteratorImpl; + template struct Foo::IteratorImpl; +} + +// PR6827 +namespace test12 { + template class Foo; + template Foo foo(T* t){ return Foo(t, true); } + + template class Foo { + public: + Foo(T*); + friend Foo foo(T*); + private: + Foo(T*, bool); // expected-note {{declared private here}} + }; + + // Should work. + int globalInt; + Foo f = foo(&globalInt); + + // Shouldn't work. + long globalLong; + template <> Foo foo(long *t) { + Foo s(&globalInt, false); // expected-error {{calling a private constructor}} + return Foo(t, true); + } +} + +// PR6514 +namespace test13 { + template class Temp> + class Role : public Temp { + friend class Temp; + int x; + }; + + template class Foo { + void foo(Role &role) { + (void) role.x; + } + }; + + template class Foo<0>; +} + +namespace test14 { + template class B; + template class A { + friend void B::foo(); + static void foo(); // expected-note {{declared private here}} + }; + + template class B { + void foo() { return A::foo(); } // expected-error {{'foo' is a private member of 'test14::A'}} + }; + + template class B; // expected-note {{in instantiation}} +} + +namespace test15 { + template class B; + template class A { + friend void B::foo(); + + // This shouldn't be misrecognized as a templated-scoped reference. + template friend void B::bar(U); + + static void foo(); // expected-note {{declared private here}} + }; + + template class B { + void foo() { return A::foo(); } // expected-error {{'foo' is a private member of 'test15::A'}} + }; + + template <> class B { + void foo() { return A::foo(); } + template void bar(U u) { + (void) A::foo(); + } + }; + + template class B; // expected-note {{in instantiation}} +} + +namespace PR10913 { + template class X; + + template void f(X *x) { + x->member = 0; + } + + template void f2(X *x) { + x->member = 0; // expected-error{{'member' is a protected member of 'PR10913::X'}} + } + + template class X { + friend void f(X *x); + friend void f2(X *x); + + protected: + int member; // expected-note{{declared protected here}} + }; + + template void f(X *); + template void f2(X *); + template void f2(X *); // expected-note{{in instantiation of function template specialization 'PR10913::f2' requested here}} +} diff --git a/clang/test/CXX/temp/temp.decls/temp.friend/p3.cpp b/clang/test/CXX/temp/temp.decls/temp.friend/p3.cpp new file mode 100644 index 0000000..0b2a25e --- /dev/null +++ b/clang/test/CXX/temp/temp.decls/temp.friend/p3.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template class A { + typedef int Member; +}; + +class B { + template friend class A; + template friend class Undeclared; + + template friend typename A::Member; // expected-error {{friend type templates must use an elaborated type}} +}; diff --git a/clang/test/CXX/temp/temp.decls/temp.friend/p4.cpp b/clang/test/CXX/temp/temp.decls/temp.friend/p4.cpp new file mode 100644 index 0000000..e036cef --- /dev/null +++ b/clang/test/CXX/temp/temp.decls/temp.friend/p4.cpp @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template +struct X1 { + friend void f6(int) { } // expected-error{{redefinition of}} \ + // expected-note{{previous definition}} +}; + +X1 x1a; +X1 x1b; // expected-note {{in instantiation of}} + +template +struct X2 { + operator int(); + + friend void f(int x) { } // expected-error{{redefinition}} \ + // expected-note{{previous definition}} +}; + +int array0[sizeof(X2)]; +int array1[sizeof(X2)]; // expected-note{{instantiation of}} + +void g() { + X2 xi; + f(xi); + X2 xf; + f(xf); +} diff --git a/clang/test/CXX/temp/temp.decls/temp.friend/p5.cpp b/clang/test/CXX/temp/temp.decls/temp.friend/p5.cpp new file mode 100644 index 0000000..63fd3df --- /dev/null +++ b/clang/test/CXX/temp/temp.decls/temp.friend/p5.cpp @@ -0,0 +1,103 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +namespace test0 { + template class A { + class Member {}; + }; + + class B { + template friend class A::Member; + }; + + A a; + B b; +} + +// rdar://problem/8204127 +namespace test1 { + template struct A; + + class C { + static void foo(); + template friend void A::f(); + }; + + template struct A { + void f() { C::foo(); } + }; + + template struct A { + void f() { C::foo(); } + }; + + template <> struct A { + void f() { C::foo(); } + }; +} + +// FIXME: these should fail! +namespace test2 { + template struct A; + + class C { + static void foo(); + template friend void A::g(); + }; + + template struct A { + void f() { C::foo(); } + }; + + template struct A { + void f() { C::foo(); } + }; + + template <> struct A { + void f() { C::foo(); } + }; +} + +// Tests 3, 4 and 5 were all noted in . +namespace test3 { + template struct A { + struct Inner { + static int foo(); + }; + }; + + template class C { + int i; + template friend struct A::Inner; + }; + + template int A::Inner::foo() { + C c; + c.i = 0; + return 0; + } + + int test = A::Inner::foo(); +} + +namespace test4 { + template struct X { + template void operator+=(U); + + template + template + friend void X::operator+=(U); + }; + + void test() { + X() += 1.0; + } +} + +namespace test5 { + template