blob: 86b560e814c28cb3a2d6716b22f84228a0cf7468 [file] [log] [blame]
Chad Rosier7a0a31c2012-02-03 01:49:51 +00001// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wno-error=non-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 {
Douglas Gregor930a9ab2011-05-21 19:26:31 +000059 E(int, ...); // expected-note 2{{implicitly declared private here}}
Anders Carlssond74d4142009-09-08 01:48:42 +000060};
61
62void t5()
63{
64 C c(10);
65
Douglas Gregor930a9ab2011-05-21 19:26:31 +000066 E e(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}} \
67 // expected-error{{calling a private constructor of class 'E'}}
68 (void)E(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}} \
69 // expected-error{{calling a private constructor of class 'E'}}
70
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000071}
Douglas Gregor75b699a2009-12-12 07:25:49 +000072
73// PR5761: unevaluated operands and the non-POD warning
74class Foo {
75 public:
76 Foo() {}
77};
78
79int Helper(...);
80const int size = sizeof(Helper(Foo()));
Douglas Gregor06d33692009-12-12 07:57:52 +000081
82namespace std {
83 class type_info { };
84}
85
86struct Base { virtual ~Base(); };
87Base &get_base(...);
88int eat_base(...);
89
90void test_typeid(Base &base) {
Eli Friedman55693fb2012-01-17 02:13:45 +000091 (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 +000092 (void)typeid(eat_base(base)); // okay
93}
Chris Lattner40378332010-05-16 04:01:30 +000094
95
96// rdar://7985267 - Shouldn't warn, doesn't actually use __builtin_va_start is
97// magic.
98
99void t6(Foo somearg, ... ) {
Chris Lattner4bb3bf92010-05-16 05:00:34 +0000100 __builtin_va_list list;
101 __builtin_va_start(list, somearg);
Chris Lattner40378332010-05-16 04:01:30 +0000102}
103
David Majnemer0adde122011-06-14 05:17:32 +0000104void t7(int n, ...) {
105 __builtin_va_list list;
106 __builtin_va_start(list, n);
107 (void)__builtin_va_arg(list, C); // expected-warning{{second argument to 'va_arg' is of non-POD type 'C'}}
108 __builtin_va_end(list);
109}
110
111struct Abstract {
112 virtual void doit() = 0; // expected-note{{unimplemented pure virtual method}}
113};
114
115void t8(int n, ...) {
116 __builtin_va_list list;
117 __builtin_va_start(list, n);
118 (void)__builtin_va_arg(list, Abstract); // expected-error{{second argument to 'va_arg' is of abstract type 'Abstract'}}
119 __builtin_va_end(list);
120}
Eli Friedman71b8fb52012-01-21 01:01:51 +0000121
122int t9(int n) {
123 // Make sure the error works in potentially-evaluated sizeof
124 return (int)sizeof(*(Helper(Foo()), (int (*)[n])0)); // expected-warning{{cannot pass object of non-POD type}}
125}