1// RUN: %clang_cc1 -std=c++1y -verify %s
2// RUN: %clang_cc1 -std=c++1y -verify %s -fdelayed-template-parsing
3
4namespace nested_local_templates_1 {
5
6template <class T> struct Outer {
7  template <class U> int outer_mem(T t, U u) {
8    struct Inner {
9      template <class V> int inner_mem(T t, U u, V v) {
10        struct InnerInner {
11          template <class W> int inner_inner_mem(W w, T t, U u, V v) {
12            return 0;
13          }
14        };
15        InnerInner().inner_inner_mem("abc", t, u, v);
16        return 0;
17      }
18    };
19    Inner i;
20    i.inner_mem(t, u, 3.14);
21    return 0;
22  }
23
24  template <class U> int outer_mem(T t, U *u);
25};
26
27template int Outer<int>::outer_mem(int, char);
28
29template <class T> template <class U> int Outer<T>::outer_mem(T t, U *u) {
30  struct Inner {
31    template <class V>
32    int inner_mem(T t, U u, V v) { //expected-note{{candidate function}}
33      struct InnerInner {
34        template <class W> int inner_inner_mem(W w, T t, U u, V v) { return 0; }
35      };
36      InnerInner().inner_inner_mem("abc", t, u, v);
37      return 0;
38    }
39  };
40  Inner i;
41  i.inner_mem(t, U{}, i);
42  i.inner_mem(t, u, 3.14); //expected-error{{no matching member function for call to 'inner}}
43  return 0;
44}
45
46template int Outer<int>::outer_mem(int, char *); //expected-note{{in instantiation of function}}
47
48} // end ns
49
50namespace nested_local_templates_2 {
51
52template <class T> struct Outer {
53  template <class U> void outer_mem(T t, U u) {
54    struct Inner {
55      template <class V> struct InnerTemplateClass {
56        template <class W>
57        void itc_mem(T t, U u, V v, W w) { //expected-note{{candidate function}}
58          struct InnerInnerInner {
59            template <class X> void iii_mem(X x) {}
60          };
61          InnerInnerInner i;
62          i.iii_mem("abc");
63        }
64      };
65    };
66    Inner i;
67    typename Inner::template InnerTemplateClass<Inner> ii;
68    ii.itc_mem(t, u, i, "jim");
69    ii.itc_mem(t, u, 0, "abd"); //expected-error{{no matching member function}}
70  }
71};
72
73template void
74Outer<int>::outer_mem(int, char); //expected-note{{in instantiation of}}
75
76}
77
78namespace more_nested_local_templates {
79
80int test() {
81  struct Local {
82    template<class U> void foo(U u) {
83      struct Inner {
84        template<class A>
85        auto operator()(A a, U u2) -> U {
86          return u2;
87        };
88      };
89      Inner GL;
90      GL('a', u );
91      GL(3.14, u );
92    }
93  };
94  Local l;
95  l.foo("nmabc");
96  return 0;
97}
98int t = test();
99}