• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wnon-pod-varargs
2 
3 extern char version[];
4 
5 class C {
6 public:
7   C(int);
8   void g(int a, ...);
9   static void h(int a, ...);
10 };
11 
12 void g(int a, ...);
13 
t1()14 void t1()
15 {
16   C c(10);
17 
18   g(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
19   g(10, version);
20 }
21 
t2()22 void t2()
23 {
24   C c(10);
25 
26   c.g(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
27   c.g(10, version);
28 
29   C::h(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
30   C::h(10, version);
31 }
32 
33 int (^block)(int, ...);
34 
t3()35 void t3()
36 {
37   C c(10);
38 
39   block(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}}
40   block(10, version);
41 }
42 
43 class D {
44 public:
45   void operator() (int a, ...);
46 };
47 
t4()48 void t4()
49 {
50   C c(10);
51 
52   D d;
53 
54   d(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
55   d(10, version);
56 }
57 
58 class E {
59   E(int, ...); // expected-note 2{{implicitly declared private here}}
60 };
61 
t5()62 void t5()
63 {
64   C c(10);
65 
66   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 
71 }
72 
73 // PR5761: unevaluated operands and the non-POD warning
74 class Foo {
75  public:
Foo()76   Foo() {}
77 };
78 
79 int Helper(...);
80 const int size = sizeof(Helper(Foo()));
81 
82 namespace std {
83   class type_info { };
84 }
85 
86 struct Base { virtual ~Base(); };
87 Base &get_base(...);
88 int eat_base(...);
89 
test_typeid(Base & base)90 void test_typeid(Base &base) {
91   (void)typeid(get_base(base)); // expected-warning{{cannot pass object of non-POD type 'Base' through variadic function; call will abort at runtime}}
92   (void)typeid(eat_base(base)); // okay
93 }
94 
95 
96 // rdar://7985267 - Shouldn't warn, doesn't actually use __builtin_va_start is
97 // magic.
98 
t6(Foo somearg,...)99 void t6(Foo somearg, ... ) {
100   __builtin_va_list list;
101   __builtin_va_start(list, somearg);
102 }
103 
t7(int n,...)104 void 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 
111 struct Abstract {
112   virtual void doit() = 0; // expected-note{{unimplemented pure virtual method}}
113 };
114 
t8(int n,...)115 void 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 }
121 
122