aboutsummaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX/cxx2c-template-template-param.cpp
blob: ed55a059bb53c6f3cf72b58f06d3457f6e8222d3 (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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// RUN:  %clang_cc1 -std=c++2c -verify %s

namespace Errors {

template <template<typename T> auto>
struct S1;
template <template<auto T> auto>
struct S2;
template <template<typename T> concept>
struct S3;
template <template<auto T> concept>
struct S4;
int a;

template <typename T>
concept C = true; // expected-note 2{{template argument refers to a concept 'C', here}}
template <typename T>
auto Var = 0; // expected-note 2{{template argument refers to a variable template 'Var', here}}

S1<1> t1; // expected-error {{template argument for template template parameter must be a variable template}}
S1<a> t2; // expected-error {{template argument for template template parameter must be a variable template}}
S1<int> t3; // expected-error {{template argument for template template parameter must be a variable template}}
S1<C> t4; // expected-error {{template argument does not refer to a variable template, or template template parameter}}
S2<1> t5; // expected-error {{template argument for template template parameter must be a variable template}}
S2<a> t6; // expected-error {{template argument for template template parameter must be a variable template}}
S2<int> t7; // expected-error {{template argument for template template parameter must be a variable template}}
S2<C> t8; // expected-error {{template argument does not refer to a variable template, or template template parameter}}
S3<1> t9; // expected-error {{template argument for template template parameter must be a concept}}
S3<a> t10; // expected-error {{template argument for template template parameter must be a concept}}
S3<int> t11; // expected-error {{template argument for template template parameter must be a concept}}
S3<Var> t12; // expected-error {{template argument does not refer to a concept, or template template parameter}}
S4<1> t13; // expected-error {{template argument for template template parameter must be a concept}}
S4<a> t14; // expected-error {{template argument for template template parameter must be a concept}}
S4<int> t15; // expected-error {{template argument for template template parameter must be a concept}}
S4<Var> t16; // expected-error {{template argument does not refer to a concept, or template template parameter}}

}

template <template<typename T> auto V> // expected-note {{previous template template parameter is here}} \
                                       // expected-error{{template argument for non-type template parameter must be an expression}}
struct S1 {
    static_assert(V<int> == 42);
    static_assert(V<const int> == 84);
    static_assert(V<double> == 0);
};
template <template<auto T> auto V>  // expected-error {{template argument for template type parameter must be a type}} \
                                    // expected-note {{previous template template parameter is here}}
struct S2 {
    static_assert(V<0> == 1);
    static_assert(V<1> == 0);
};
template <template<typename T> concept C > // expected-error {{template argument for non-type template parameter must be an expression}} \
                                           // expected-note {{previous template template parameter is here}}
struct S3 {
    static_assert(C<int>);
};
template <template<auto> concept C> // expected-error {{template argument for template type parameter must be a type}} \
                                    // expected-note {{previous template template parameter is here}}
struct S4 {
    static_assert(C<0>);
};

template <typename T> // expected-note {{template parameter is declared here}}
concept C = true;

template <auto I> // expected-note {{template parameter is declared here}}
concept CI = true;

template <typename T> // expected-note {{template parameter is declared here}}
constexpr auto Var = 42;
template <typename T>
constexpr auto Var<const T> = 84;
template <>
constexpr auto Var<double> = 0;

template <auto N> // expected-note {{template parameter is declared here}}
constexpr auto Var2 = 0;
template <auto N>
requires (N%2 == 0)
constexpr auto Var2<N> = 1;

void test () {
    S1<Var2> sE; // expected-note {{template template argument has different template parameters than its corresponding template template parameter}}
    S2<Var>  sE; // expected-note {{template template argument has different template parameters than its corresponding template template parameter}}
    S1<Var> s1;
    S2<Var2> s2;
    S3<C> s3;
    S4<C> sE; // expected-note {{template template argument has different template parameters than its corresponding template template parameter}}
    S4<CI> s4;
    S3<CI> sE; // expected-note {{template template argument has different template parameters than its corresponding template template parameter}}
}


namespace template_type_constraints {


template <typename T>
concept Unary = true;
template <typename T, typename = int>
concept BinaryDefaulted = true;

template <typename T>
concept UnaryFalse = false; // expected-note 3{{because 'false' evaluated to false}}
template <typename T, typename = int>
concept BinaryDefaultedFalse = false;

template <template <typename...> concept C, typename T>
struct S {
    template <C TT> // expected-note {{because 'int' does not satisfy 'UnaryFalse'}}
    void f(TT); // expected-note {{ignored}}
    void g(C auto); // expected-note {{ignored}} \
                    // expected-note {{because 'int' does not satisfy 'UnaryFalse'}}

    auto h() -> C auto { // expected-error {{deduced type 'int' does not satisfy 'UnaryFalse'}}
        return 0;
    };

    void test() {
        C auto a = 0;
    }
};

template <template <typename...> concept C, typename T>
struct SArg {
    template <C<int> TT>
    void f(TT);
    void g(C<int> auto);

    auto h() -> C<int> auto {
        return 0;
    };
    void test() {
        C<int> auto a = 0;
    }
};

void test() {
    S<Unary, int> s;
    s.f(0);
    s.g(0);
    s.h();
    S<BinaryDefaulted, int> s2;
    s2.f(0);
    s2.g(0);
    s2.h();

    SArg<BinaryDefaulted, int> s3;
    s3.f(0);
    s3.g(0);
    s3.h();
}

void test_errors() {
    S<UnaryFalse, int> s;
    s.f(0); // expected-error {{no matching member function for call to 'f'}}
    s.g(0); // expected-error {{no matching member function for call to 'g'}}
    s.h(); // expected-note {{in instantiation of member function 'template_type_constraints::S<template_type_constraints::UnaryFalse, int>::h'}}
}

}

template <typename T>
concept Unary = true;
template <typename T, typename = int>
concept BinaryDefaulted = true;

template <typename T>
concept UnaryFalse = false; // expected-note 3{{because 'false' evaluated to false}}
template <typename T, typename = int>
concept BinaryDefaultedFalse = false;

template <template <typename...> concept C, typename T>
struct S {
    template <C TT> // expected-note {{because 'int' does not satisfy 'UnaryFalse'}}
    void f(TT); // expected-note {{ignored}}
    void g(C auto); // expected-note {{ignored}} \
                    // expected-note {{because 'int' does not satisfy 'UnaryFalse'}}

    auto h() -> C auto { // expected-error {{deduced type 'int' does not satisfy 'UnaryFalse'}}
        return 0;
    };

    void test() {
        C auto a = 0;
    }
};

template <template <typename...> concept C, typename T>
struct SArg {
    template <C<int> TT>
    void f(TT);
    void g(C<int> auto);

    auto h() -> C<int> auto {
        return 0;
    };
    void test() {
        C<int> auto a = 0;
    }
};

void test_args() {
    S<Unary, int> s;
    s.f(0);
    s.g(0);
    s.h();
    S<BinaryDefaulted, int> s2;
    s2.f(0);
    s2.g(0);
    s2.h();

    SArg<BinaryDefaulted, int> s3;
    s3.f(0);
    s3.g(0);
    s3.h();
}

void test_errors() {
    S<UnaryFalse, int> s;
    s.f(0); // expected-error {{no matching member function for call to 'f'}}
    s.g(0); // expected-error {{no matching member function for call to 'g'}}
    s.h(); // expected-note {{in instantiation of member function 'S<UnaryFalse, int>::h'}}
}

namespace non_type {

template <auto>
concept Unary = true;

template <template <auto> concept C>
struct S {
    template <C Foo> // expected-error {{concept named in type constraint is not a type concept}}
    void f();
    // FIXME, bad diagnostic
    void g(C auto);  // expected-error{{concept named in type constraint is not a type concept}}
    auto h() -> C auto {  // expected-error{{concept named in type constraint is not a type concept}}
    }
    void i() {
        C auto a = 0;  // expected-error{{concept named in type constraint is not a type concept}}
    }
};

}

namespace default_args {

template <typename T>
concept Concept = false; // expected-note 2{{template argument refers to a concept 'Concept', here}} \
                         // expected-note 2{{because 'false' evaluated to false}}

template <typename T>
constexpr auto Var = false; // expected-note 2{{template argument refers to a variable template 'Var', here}}

template <typename T>
struct Type; // expected-note 2{{template argument refers to a class template 'Type', here}}


template <template <typename> auto = Concept> // expected-error {{template argument does not refer to a variable template, or template template parameter}}
struct E1;

template <template <typename> auto  = Type> // expected-error {{template argument does not refer to a variable template, or template template parameter}}
struct E2;

template <template <typename> typename = Concept> // expected-error {{template argument does not refer to a class or alias template, or template template parameter}}
struct E3;

template <template <typename> typename  = Var> // expected-error {{template argument does not refer to a class or alias template, or template template parameter}}
struct E4;

template <template <typename> concept  = Var> // expected-error {{template argument does not refer to a concept, or template template parameter}}
struct E4;

template <template <typename> concept  = Type> // expected-error {{template argument does not refer to a concept, or template template parameter}}
struct E4;

template <
    template <typename> concept TConcept, // expected-note 2{{template argument refers to a concept 'TConcept', here}}
    template <typename> auto TVar, // expected-note 2{{template argument refers to a variable template 'TVar', here}}
    template <typename> typename TType // expected-note 2{{template argument refers to a class template 'TType', here}}
>
struct Nested {
    template <template <typename> auto = TConcept> // expected-error {{template argument does not refer to a variable template, or template template parameter}}
    struct E1;

    template <template <typename> auto  = TType> // expected-error {{template argument does not refer to a variable template, or template template parameter}}
    struct E2;

    template <template <typename> typename = TConcept> // expected-error {{template argument does not refer to a class or alias template, or template template parameter}}
    struct E3;

    template <template <typename> typename  = TVar> // expected-error {{template argument does not refer to a class or alias template, or template template parameter}}
    struct E4;

    template <template <typename> concept  = TVar> // expected-error {{template argument does not refer to a concept, or template template parameter}}
    struct E4;

    template <template <typename> concept  = TType> // expected-error {{template argument does not refer to a concept, or template template parameter}}
    struct E4;
};


template <template <typename> concept C = Concept>
struct TestDefaultConcept {
    template <template <typename> concept CC = C>
    void f() {
        static_assert(C<int>); // expected-error {{static assertion failed}} \
                               // expected-note {{because 'int' does not satisfy 'Concept'}}
        static_assert(CC<int>);  // expected-error {{static assertion failed}} \
                                 // expected-note {{because 'int' does not satisfy 'Concept'}}
    }
};
void do_test_concept() {
    TestDefaultConcept<>{}.f(); // expected-note {{in instantiation}}
}

template <template <typename> auto V = Var>
struct TestDefaultVar {
    template <template <typename> auto VV = V>
    void f() {
        static_assert(V<int>); // expected-error {{static assertion failed}}
        static_assert(VV<int>); // expected-error {{static assertion failed}}
    }
};
void do_test_var() {
    TestDefaultVar<>{}.f(); // expected-note {{in instantiation}}
}

}

namespace TTPDependence {
template <template <typename... > concept C>
concept A = C<>;
template <template <typename... > concept C>
concept B = C<int>;

template <template <typename... > auto Var>
concept C = Var<>;
template <template <typename... > auto Var>
concept D = Var<int>;

}

namespace InvalidName {
template <typename T, template <typename> concept C>
concept A = C<T>; // expected-note {{here}}

template <A<concept missing<int>> T> // expected-error {{expected expression}} \
                                     // expected-error {{too few template arguments for concept 'A'}} \
                                     // expected-error {{unknown type name 'T'}}  \
                                     // expected-error {{expected unqualified-id}}
auto f();
}