xref: /llvm-project/clang/test/CXX/temp/temp.decls/temp.variadic/sizeofpack.cpp (revision d44518c1cc2e5c598f51cbdd32e6d18a12b1a4bb)
1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
3 // expected-no-diagnostics
4 
5 namespace pr12262 {
6 
7 template<typename T, typename... Ts>
8 void abc1(int (*xxx)[sizeof ... (Ts) + 1]);
9 
10 void qq1 () {
11   abc1<int>(0);
12   abc1<int,double>(0);
13 }
14 
15 
16 template <unsigned N> class array {};
17 
18 
19 template<typename T, typename... Types>
20 array<sizeof...(Types)> make_array1(Types&&... args);
21 
22 void qq2 () {
23   array<1> arr = make_array1<int>(1);
24   array<3> arr2 = make_array1<int>(1,array<5>(),0.1);
25 }
26 
27 
28 template<typename T, typename... Types>
29 int make_array(array<sizeof...(Types)>&, Types... args);
30 
31 void qq3 () {
32   array<1> a1;
33   int aa1 = make_array<int>(a1,1);
34   array<2> a2;
35   int aa2 = make_array<int>(a2, 0L, "abc");
36 }
37 
38 
39 template<typename ... Ts>
40 struct AAA {
41   template<typename T, typename... Types>
42   static array<sizeof...(Types)> make_array(Types ... args);
43 };
44 
45 void qq4 () {
46   array<2> arr2 = AAA<int, int>::make_array<int>(1,2);
47 }
48 
49 }
50 
51 
52 namespace pr12439 {
53 
54 template<class... Members>
55 struct X {
56   template<int Idx>
57   using get_t = decltype(sizeof...(Members));
58 
59   template<int i>
60   get_t<i> get();
61 };
62 
63 template<class... Members>
64 template<int i>
65 typename X<Members...>::template get_t<i> X<Members...>::get()
66 {
67   return 0;
68 }
69 
70 }
71 
72 
73 namespace pr13272 {
74 
75 template<bool B, class T = void>
76 struct enable_if { };
77 
78 template<class T> struct enable_if<true, T> {
79   typedef T type;
80 };
81 
82 class Exception {};
83 
84 template<class Ex, typename... Args>
85 void cxx_throw(typename enable_if<(sizeof...(Args) > 0), const char *>::type fmt, Args&&... args) {
86   return;
87 }
88 
89 void test() {
90   cxx_throw<Exception>("Youpi",1);
91 }
92 
93 }
94 
95 
96 namespace pr13817 {
97 
98 template <unsigned>
99 struct zod;
100 
101 template <>
102 struct zod<1> {};
103 
104 template <typename T, typename ... Ts>
105 zod<sizeof...(Ts)> make_zod(Ts ...) {
106   return zod<sizeof...(Ts)>();
107 }
108 
109 int main(int argc, char *argv[])
110 {
111   make_zod<int>(1);
112   return 0;
113 }
114 
115 }
116 
117 
118 namespace pr14273 {
119 
120 template<typename T, int i>
121 struct myType
122 { };
123 
124 template<typename T, typename... Args>
125 struct Counter
126 {
127   static const int count = 1 + Counter<Args...>::count;
128 };
129 
130 template<typename T>
131 struct Counter<T>
132 {
133   static const int count = 1;
134 };
135 
136 template<typename Arg, typename... Args>
137 myType<Arg, sizeof...(Args)>* make_array_with_type(const Args&... args)
138 {
139   return 0;
140 }
141 
142 void func(void)
143 {
144   make_array_with_type<char>(1,2,3);
145 }
146 
147 }
148 
149 
150 namespace pr15112
151 {
152   template<bool, typename _Tp = void>
153     struct enable_if
154     { };
155   template<typename _Tp>
156     struct enable_if<true,_Tp>
157     { typedef _Tp type; };
158 
159   typedef __typeof__(sizeof(int)) size_t;
160 
161   template <size_t n, typename T, typename... Args>
162   struct is_array_of { static const bool value = true; };
163 
164   struct cpu { using value_type = void; };
165 
166   template <size_t Order, typename T>
167   struct coords_alias { typedef T type; };
168 
169   template <size_t Order, typename MemoryTag>
170   using coords = typename coords_alias<Order, MemoryTag>::type;
171 
172   template <typename MemTag, typename... Args>
173   typename enable_if<is_array_of<sizeof...(Args), size_t, Args...>::value,
174                      coords<sizeof...(Args), MemTag>>::type
175     mkcoords(Args... args);
176 
177   auto c1 = mkcoords<cpu>(0ul, 0ul, 0ul);
178 }
179 
180 
181 namespace pr12699 {
182 
183 template<bool B>
184 struct bool_constant
185 {
186   static const bool value = B;
187 };
188 
189 template<typename... A>
190 struct F
191 {
192   template<typename... B>
193     using SameSize = bool_constant<sizeof...(A) == sizeof...(B)>;
194 
195   template<typename... B, typename = SameSize<B...>>
196   F(B...) { }
197 };
198 
199 void func()
200 {
201   F<int> f1(3);
202 }
203 
204 }
205 
206 #if __cplusplus >= 202002L
207 namespace GH81436 {
208 
209 template <class E> struct Bar;
210 
211 template <class E>
212 Bar(E) -> Bar<E>;
213 
214 template <int> struct Foo {};
215 
216 // Bar<Ts> doesn't have to be of a complete type.
217 template <class... Ts>
218 auto func() requires requires(Bar<Ts> ...init_lists) {
219   sizeof...(init_lists) > 0;
220 } {}
221 
222 void f() { func<int>(); }
223 
224 } // namespace GH81436
225 #endif
226