1 | // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s |
2 | |
3 | // Test parsing + semantic analysis |
4 | template<typename ...Types> struct count_types { |
5 | static const unsigned value = sizeof...(Types); |
6 | }; |
7 | |
8 | template<int ...Values> struct count_ints { |
9 | static const unsigned value = sizeof...(Values); |
10 | }; |
11 | |
12 | // Test instantiation |
13 | int check_types[count_types<short, int, long>::value == 3? 1 : -1]; |
14 | int check_ints[count_ints<1, 2, 3, 4, 5>::value == 5? 1 : -1]; |
15 | |
16 | // Test instantiation involving function parameter packs. |
17 | struct any { |
18 | template<typename T> any(T); |
19 | }; |
20 | |
21 | template<typename ...Inits> |
22 | void init_me(Inits ...inits) { |
23 | any array[sizeof...(inits)] = { inits... }; |
24 | } |
25 | |
26 | template void init_me<int, float, double*>(int, float, double*); |
27 | |
28 | // Test parser and semantic recovery. |
29 | template<int Value> struct count_ints_2 { |
30 | static const unsigned value = sizeof...(Value); // expected-error{{'Value' does not refer to the name of a parameter pack}} |
31 | }; |
32 | |
33 | template<typename ...Types> // expected-note{{parameter pack 'Types' declared here}} |
34 | struct count_types_2 { |
35 | static const unsigned value = sizeof... Type; // expected-error{{missing parentheses around the size of parameter pack 'Type'}} \ |
36 | // expected-error{{Type' does not refer to the name of a parameter pack; did you mean 'Types'?}} |
37 | }; |
38 | |
39 | |