p5.cpp revision 8e8fb3be5bd78f0564444eca02b404566a5f3b5d
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2// expected-no-diagnostics
3
4namespace test0 {
5  template <class T> class A {
6    class Member {};
7  };
8
9  class B {
10    template <class T> friend class A<T>::Member;
11  };
12
13  A<int> a;
14  B b;
15}
16
17// rdar://problem/8204127
18namespace test1 {
19  template <class T> struct A;
20
21  class C {
22    static void foo();
23    template <class T> friend void A<T>::f();
24  };
25
26  template <class T> struct A {
27    void f() { C::foo(); }
28  };
29
30  template <class T> struct A<T*> {
31    void f() { C::foo(); }
32  };
33
34  template <> struct A<char> {
35    void f() { C::foo(); }
36  };
37}
38
39// FIXME: these should fail!
40namespace test2 {
41  template <class T> struct A;
42
43  class C {
44    static void foo();
45    template <class T> friend void A<T>::g();
46  };
47
48  template <class T> struct A {
49    void f() { C::foo(); }
50  };
51
52  template <class T> struct A<T*> {
53    void f() { C::foo(); }
54  };
55
56  template <> struct A<char> {
57    void f() { C::foo(); }
58  };
59}
60
61// Tests 3, 4 and 5 were all noted in <rdar://problem/8540527>.
62namespace test3 {
63  template <class T> struct A {
64    struct Inner {
65      static int foo();
66    };
67  };
68
69  template <class U> class C {
70    int i;
71    template <class T> friend struct A<T>::Inner;
72  };
73
74  template <class T> int A<T>::Inner::foo() {
75    C<int> c;
76    c.i = 0;
77    return 0;
78  }
79
80  int test = A<int>::Inner::foo();
81}
82
83namespace test4 {
84  template <class T> struct X {
85    template <class U> void operator+=(U);
86
87    template <class V>
88    template <class U>
89    friend void X<V>::operator+=(U);
90  };
91
92  void test() {
93    X<int>() += 1.0;
94  }
95}
96
97namespace test5 {
98  template<template <class> class T> struct A {
99    template<template <class> class T> friend void A<T>::foo();
100  };
101
102  template <class> struct B {};
103  template class A<B>;
104}
105