aboutsummaryrefslogtreecommitdiff
path: root/clang/test/SemaTemplate/nested-name-spec-template.cpp
blob: f99fa4b46485938a29f6a27dda3eb07d42a765d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-c++20-extensions
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s

namespace N {
  namespace M {
    template<typename T> struct Promote;

    template<> struct Promote<short> {
      typedef int type;
    };

    template<> struct Promote<int> {
      typedef int type;
    };

    template<> struct Promote<float> {
      typedef double type;
    };

    Promote<short>::type *ret_intptr(int* ip) { return ip; }
    Promote<int>::type *ret_intptr2(int* ip) { return ip; }
  }

  M::Promote<int>::type *ret_intptr3(int* ip) { return ip; }
  M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; }
  M::template Promote<int> pi;
}

N::M::Promote<int>::type *ret_intptr5(int* ip) { return ip; }
::N::M::Promote<int>::type *ret_intptr6(int* ip) { return ip; }


N::M::template; // expected-error{{expected unqualified-id}}
N::M::template Promote; // expected-error{{expected unqualified-id}}

namespace N {
  template<typename T> struct A;

  template<>
  struct A<int> {
    struct X;
  };

  struct B; // expected-note{{declared as a non-template here}}
}

struct ::N::A<int>::X {
  int foo;
};

template<typename T>
struct TestA {
  typedef typename N::template B<T>::type type; // expected-error{{'B' following the 'template' keyword does not refer to a template}}
};

// Reduced from a Boost failure.
namespace test1 {
  template <class T> struct pair {
    T x;
    T y;

    static T pair<T>::* const mem_array[2];
  };

  template <class T>
  T pair<T>::* const pair<T>::mem_array[2] = { &pair<T>::x, &pair<T>::y };
}

typedef int T;
namespace N1 {
  template<typename T> T f0();
}

template<typename T> T N1::f0() { }

namespace PR7385 {
  template< typename > struct has_xxx0
  {
    template< typename > struct has_xxx0_introspect
    {
      template< typename > struct has_xxx0_substitute ;
      template< typename V >
      int int00( has_xxx0_substitute < typename V::template xxx< > > = 0 );
    };
    static const int value = has_xxx0_introspect<int>::value; // expected-error{{no member named 'value'}}
    typedef int type;
  };

  has_xxx0<int>::type t; // expected-note{{instantiation of}}
}

namespace PR7725 {
  template<class ignored> struct TypedefProvider;
  template<typename T>
  struct TemplateClass : public TypedefProvider<T>
  {
    void PrintSelf() {
      TemplateClass::Test::PrintSelf();
    }
  };
}

namespace PR9226 {
  template<typename a>
  void nt() // expected-note{{function template 'nt' declared here}}
  { nt<>:: } // expected-error{{qualified name refers into a specialization of function template 'nt'}} \
  // expected-error{{expected unqualified-id}}

  template<typename T>
  void f(T*); // expected-note{{function template 'f' declared here}}

  template<typename T>
  void f(T*, T*); // expected-note{{function template 'f' declared here}}

  void g() {
    f<int>:: // expected-error{{qualified name refers into a specialization of function template 'f'}}
  } // expected-error{{expected unqualified-id}}

  struct X {
    template<typename T> void f(); // expected-note{{function template 'f' declared here}}
  };

  template<typename T, typename U>
  struct Y {
    typedef typename T::template f<U> type; // expected-error{{template name refers to non-type template 'PR9226::X::template f'}}
  };

  Y<X, int> yxi; // expected-note{{in instantiation of template class 'PR9226::Y<PR9226::X, int>' requested here}}
}

namespace PR9449 {
  template <typename T>
  struct s; // expected-note{{template is declared here}}

  template <typename T>
  void f() {
    int s<T>::template n<T>::* f; // expected-error{{implicit instantiation of undefined template 'PR9449::s<int>'}}
  }

  template void f<int>(); // expected-note{{in instantiation of}}
}

namespace sugared_template_instantiation {
  // Test that we ignore local qualifiers.
  template <class A1, class = typename A1::type1> struct A {};
  struct B { typedef int type1; };
  typedef A<const B> type2;
} // namespace sugated_template_instantiation

namespace unresolved_using {
  template <class> struct A {
    struct B {
      typedef int X;
    };
  };
  template <class T> struct C : A<T> {
    using typename A<T>::B;
    typedef typename B::X Y;
  };
  template struct C<int>;
} // namespace unresolved_using

#if __cplusplus >= 201703L
namespace SubstTemplateTypeParmPackType {
  template <int...> struct A {};

  template <class... Ts> void f() {
    []<int ... Is>(A<Is...>) { (Ts::g(Is) && ...); }(A<0>{});
  };

  struct B { static void g(int); };

  template void f<B>();
} // namespace SubstTemplateTypeParmPackType
#endif

namespace DependentUnaryTransform {
  template <class T> using decay_t = __decay(T);
  template <class, class> struct A;
  template <class T> struct A<T, typename decay_t<T>::X>;
} // namespace DependentUnaryTransform

namespace DependentSizedArray {
  template <int V> using Z = int[V];
  template <class, class> struct A;
  template <class T> struct A<T, typename Z<T(0)>::X>;
} // namespace DependentUnaryTransform

namespace GH155281 {
  template <bool> struct enable_if;
  template <class _Tp, _Tp> struct integral_constant;
  template <typename> struct conjunction;
  template <typename T> using value_type_t = T;
  template <class Check> using require_t = typename enable_if<Check::value>::type;
  template <template <class> class, template <class> class,
            template <class> class, class... Check>
  using container_type_check_base =
      integral_constant<bool, conjunction<Check...>::value>;
  template <typename> struct is_std_vector;
  template <template <class> class TypeCheck, class... Check>
  using require_std_vector_vt =
      require_t<container_type_check_base<is_std_vector, value_type_t, TypeCheck,
                                          Check...> >;
  template <typename, typename> class vector_seq_view;
  namespace internal {
  template <typename> using is_matrix_or_std_vector = int;
  }
  template <typename T>
  class vector_seq_view<
      T, require_std_vector_vt<internal::is_matrix_or_std_vector, T> >;
} // namespace GH155281