blob: 55ec9418cd47258545b7501dc45910e6edb26ae6 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wnon-pod-varargs
Anders Carlsson906fed02009-01-13 05:48:52 +00002
Anders Carlssondce5e2c2009-01-16 16:48:51 +00003extern char version[];
4
Anders Carlsson906fed02009-01-13 05:48:52 +00005class C {
6public:
7 C(int);
8 void g(int a, ...);
9 static void h(int a, ...);
10};
11
12void g(int a, ...);
13
14void t1()
15{
16 C c(10);
17
John McCall7c2342d2010-03-10 11:27:22 +000018 g(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
Anders Carlssondce5e2c2009-01-16 16:48:51 +000019 g(10, version);
Anders Carlsson906fed02009-01-13 05:48:52 +000020}
21
22void t2()
23{
24 C c(10);
25
John McCall7c2342d2010-03-10 11:27:22 +000026 c.g(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
Anders Carlssondce5e2c2009-01-16 16:48:51 +000027 c.g(10, version);
Anders Carlsson906fed02009-01-13 05:48:52 +000028
John McCall7c2342d2010-03-10 11:27:22 +000029 C::h(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
Anders Carlssondce5e2c2009-01-16 16:48:51 +000030 C::h(10, version);
Anders Carlsson906fed02009-01-13 05:48:52 +000031}
32
33int (^block)(int, ...);
34
35void t3()
36{
37 C c(10);
38
John McCall7c2342d2010-03-10 11:27:22 +000039 block(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}}
Anders Carlssondce5e2c2009-01-16 16:48:51 +000040 block(10, version);
Anders Carlsson906fed02009-01-13 05:48:52 +000041}
42
43class D {
44public:
45 void operator() (int a, ...);
46};
47
48void t4()
49{
50 C c(10);
51
52 D d;
53
John McCall7c2342d2010-03-10 11:27:22 +000054 d(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
Anders Carlssondce5e2c2009-01-16 16:48:51 +000055 d(10, version);
Anders Carlsson906fed02009-01-13 05:48:52 +000056}
Anders Carlssond74d4142009-09-08 01:48:42 +000057
58class E {
59 E(int, ...);
60};
61
62void t5()
63{
64 C c(10);
65
John McCall7c2342d2010-03-10 11:27:22 +000066 E e(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}}
67 (void)E(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}}
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000068}
Douglas Gregor75b699a2009-12-12 07:25:49 +000069
70// PR5761: unevaluated operands and the non-POD warning
71class Foo {
72 public:
73 Foo() {}
74};
75
76int Helper(...);
77const int size = sizeof(Helper(Foo()));
Douglas Gregor06d33692009-12-12 07:57:52 +000078
79namespace std {
80 class type_info { };
81}
82
83struct Base { virtual ~Base(); };
84Base &get_base(...);
85int eat_base(...);
86
87void test_typeid(Base &base) {
John McCall7c2342d2010-03-10 11:27:22 +000088 (void)typeid(get_base(base)); // expected-warning{{cannot pass object of non-POD type 'Base' through variadic function; call will abort at runtime}}
Douglas Gregor06d33692009-12-12 07:57:52 +000089 (void)typeid(eat_base(base)); // okay
90}
Chris Lattner40378332010-05-16 04:01:30 +000091
92
93// rdar://7985267 - Shouldn't warn, doesn't actually use __builtin_va_start is
94// magic.
95
96void t6(Foo somearg, ... ) {
Chris Lattner4bb3bf92010-05-16 05:00:34 +000097 __builtin_va_list list;
98 __builtin_va_start(list, somearg);
Chris Lattner40378332010-05-16 04:01:30 +000099}
100