1 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wno-error=non-pod-varargs
2 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++98 %s -Wno-error=non-pod-varargs
3 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++11 %s -Wno-error=non-pod-varargs
5 // Check that the warning is still there under -fms-compatibility.
6 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wno-error=non-pod-varargs -fms-compatibility
7 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++98 %s -Wno-error=non-pod-varargs -fms-compatibility
8 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++11 %s -Wno-error=non-pod-varargs -fms-compatibility
10 extern char version
[];
16 static void h(int a
, ...);
26 #if __cplusplus <= 199711L
27 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
32 void (*ptr
)(int, ...) = g
;
34 #if __cplusplus <= 199711L
35 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
46 #if __cplusplus <= 199711L
47 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
52 void (C::*ptr
)(int, ...) = &C::g
;
54 #if __cplusplus <= 199711L
55 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
58 (c
.*ptr
)(10, version
);
61 #if __cplusplus <= 199711L
62 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
67 void (*static_ptr
)(int, ...) = &C::h
;
69 #if __cplusplus <= 199711L
70 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
73 static_ptr(10, version
);
76 int (^block
)(int, ...);
83 #if __cplusplus <= 199711L
84 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}}
92 void operator() (int a
, ...);
102 #if __cplusplus <= 199711L
103 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
110 E(int, ...); // expected-note 2{{implicitly declared private here}}
118 #if __cplusplus <= 199711L
119 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}}
121 // expected-error@-4 {{calling a private constructor of class 'E'}}
123 #if __cplusplus <= 199711L
124 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}}
126 // expected-error@-4 {{calling a private constructor of class 'E'}}
130 // PR5761: unevaluated operands and the non-POD warning
137 const int size
= sizeof(Helper(Foo()));
143 struct Base
{ virtual ~Base(); };
147 void test_typeid(Base
&base
) {
148 (void)typeid(get_base(base
));
149 #if __cplusplus <= 199711L
150 // expected-warning@-2 {{cannot pass object of non-POD type 'Base' through variadic function; call will abort at runtime}}
152 // expected-warning@-4 {{cannot pass object of non-trivial type 'Base' through variadic function; call will abort at runtime}}
154 // expected-warning@-6 {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}}
155 (void)typeid(eat_base(base
)); // okay
159 // rdar://7985267 - Shouldn't warn, doesn't actually use __builtin_va_start is
162 void t6(Foo somearg
, ... ) {
163 __builtin_va_list list
;
164 __builtin_va_start(list
, somearg
);
167 // __builtin_stdarg_start is a compatibility alias for __builtin_va_start,
168 // it should behave the same
169 void t6b(Foo somearg
, ... ) {
170 __builtin_va_list list
;
171 __builtin_stdarg_start(list
, somearg
); // second argument to 'va_start' is not the last named parameter [-Wvarargs]
174 void t7(int n
, ...) {
175 __builtin_va_list list
;
176 __builtin_va_start(list
, n
);
177 (void)__builtin_va_arg(list
, C
); // expected-warning{{second argument to 'va_arg' is of non-POD type 'C'}}
178 __builtin_va_end(list
);
182 virtual void doit() = 0; // expected-note{{unimplemented pure virtual method}}
185 void t8(int n
, ...) {
186 __builtin_va_list list
;
187 __builtin_va_start(list
, n
);
188 (void)__builtin_va_arg(list
, Abstract
); // expected-error{{second argument to 'va_arg' is of abstract type 'Abstract'}}
189 __builtin_va_end(list
);
193 // Make sure the error works in potentially-evaluated sizeof
194 return (int)sizeof(*(Helper(Foo()), (int (*)[n
])0));
195 #if __cplusplus <= 199711L
196 // expected-warning@-2 {{cannot pass object of non-POD type 'Foo' through variadic function; call will abort at runtime}}
207 void operator()(F
, ...);
219 typedef void(*function_ptr
)(int, ...);
220 typedef void(C::*member_ptr
)(int, ...);
221 typedef void(^block_ptr
)(int, ...);
223 function_ptr
get_f_ptr();
224 member_ptr
get_m_ptr();
225 block_ptr
get_b_ptr();
227 function_ptr arr_f_ptr
[5];
228 member_ptr arr_m_ptr
[5];
229 block_ptr arr_b_ptr
[5];
234 (get_f_ptr())(10, c
);
235 #if __cplusplus <= 199711L
236 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
238 (get_f_ptr())(10, version
);
240 (c
.*get_m_ptr())(10, c
);
241 #if __cplusplus <= 199711L
242 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
244 (c
.*get_m_ptr())(10, version
);
246 (get_b_ptr())(10, c
);
247 #if __cplusplus <= 199711L
248 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}}
251 (get_b_ptr())(10, version
);
253 (arr_f_ptr
[3])(10, c
);
254 #if __cplusplus <= 199711L
255 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
258 (arr_f_ptr
[3])(10, version
);
260 (c
.*arr_m_ptr
[3])(10, c
);
261 #if __cplusplus <= 199711L
262 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
265 (c
.*arr_m_ptr
[3])(10, version
);
267 (arr_b_ptr
[3])(10, c
);
268 #if __cplusplus <= 199711L
269 // expected-warning@-2 {{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}}
271 (arr_b_ptr
[3])(10, version
);