Chad Rosier | 7a0a31c | 2012-02-03 01:49:51 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wno-error=non-pod-varargs |
Anders Carlsson | 906fed0 | 2009-01-13 05:48:52 +0000 | [diff] [blame] | 2 | |
Anders Carlsson | dce5e2c | 2009-01-16 16:48:51 +0000 | [diff] [blame] | 3 | extern char version[]; |
| 4 | |
Anders Carlsson | 906fed0 | 2009-01-13 05:48:52 +0000 | [diff] [blame] | 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 | |
| 14 | void t1() |
| 15 | { |
| 16 | C c(10); |
| 17 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 18 | g(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} |
Anders Carlsson | dce5e2c | 2009-01-16 16:48:51 +0000 | [diff] [blame] | 19 | g(10, version); |
Anders Carlsson | 906fed0 | 2009-01-13 05:48:52 +0000 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | void t2() |
| 23 | { |
| 24 | C c(10); |
| 25 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 26 | c.g(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} |
Anders Carlsson | dce5e2c | 2009-01-16 16:48:51 +0000 | [diff] [blame] | 27 | c.g(10, version); |
Anders Carlsson | 906fed0 | 2009-01-13 05:48:52 +0000 | [diff] [blame] | 28 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 29 | C::h(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}} |
Anders Carlsson | dce5e2c | 2009-01-16 16:48:51 +0000 | [diff] [blame] | 30 | C::h(10, version); |
Anders Carlsson | 906fed0 | 2009-01-13 05:48:52 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | int (^block)(int, ...); |
| 34 | |
| 35 | void t3() |
| 36 | { |
| 37 | C c(10); |
| 38 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 39 | block(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}} |
Anders Carlsson | dce5e2c | 2009-01-16 16:48:51 +0000 | [diff] [blame] | 40 | block(10, version); |
Anders Carlsson | 906fed0 | 2009-01-13 05:48:52 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | class D { |
| 44 | public: |
| 45 | void operator() (int a, ...); |
| 46 | }; |
| 47 | |
| 48 | void t4() |
| 49 | { |
| 50 | C c(10); |
| 51 | |
| 52 | D d; |
| 53 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 54 | d(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}} |
Anders Carlsson | dce5e2c | 2009-01-16 16:48:51 +0000 | [diff] [blame] | 55 | d(10, version); |
Anders Carlsson | 906fed0 | 2009-01-13 05:48:52 +0000 | [diff] [blame] | 56 | } |
Anders Carlsson | d74d414 | 2009-09-08 01:48:42 +0000 | [diff] [blame] | 57 | |
| 58 | class E { |
Douglas Gregor | 930a9ab | 2011-05-21 19:26:31 +0000 | [diff] [blame] | 59 | E(int, ...); // expected-note 2{{implicitly declared private here}} |
Anders Carlsson | d74d414 | 2009-09-08 01:48:42 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | void t5() |
| 63 | { |
| 64 | C c(10); |
| 65 | |
Douglas Gregor | 930a9ab | 2011-05-21 19:26:31 +0000 | [diff] [blame] | 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 | |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 71 | } |
Douglas Gregor | 75b699a | 2009-12-12 07:25:49 +0000 | [diff] [blame] | 72 | |
| 73 | // PR5761: unevaluated operands and the non-POD warning |
| 74 | class Foo { |
| 75 | public: |
| 76 | Foo() {} |
| 77 | }; |
| 78 | |
| 79 | int Helper(...); |
| 80 | const int size = sizeof(Helper(Foo())); |
Douglas Gregor | 06d3369 | 2009-12-12 07:57:52 +0000 | [diff] [blame] | 81 | |
| 82 | namespace std { |
| 83 | class type_info { }; |
| 84 | } |
| 85 | |
| 86 | struct Base { virtual ~Base(); }; |
| 87 | Base &get_base(...); |
| 88 | int eat_base(...); |
| 89 | |
| 90 | void test_typeid(Base &base) { |
Eli Friedman | 55693fb | 2012-01-17 02:13:45 +0000 | [diff] [blame] | 91 | (void)typeid(get_base(base)); // expected-warning{{cannot pass object of non-POD type 'Base' through variadic function; call will abort at runtime}} |
Douglas Gregor | 06d3369 | 2009-12-12 07:57:52 +0000 | [diff] [blame] | 92 | (void)typeid(eat_base(base)); // okay |
| 93 | } |
Chris Lattner | 4037833 | 2010-05-16 04:01:30 +0000 | [diff] [blame] | 94 | |
| 95 | |
| 96 | // rdar://7985267 - Shouldn't warn, doesn't actually use __builtin_va_start is |
| 97 | // magic. |
| 98 | |
| 99 | void t6(Foo somearg, ... ) { |
Chris Lattner | 4bb3bf9 | 2010-05-16 05:00:34 +0000 | [diff] [blame] | 100 | __builtin_va_list list; |
| 101 | __builtin_va_start(list, somearg); |
Chris Lattner | 4037833 | 2010-05-16 04:01:30 +0000 | [diff] [blame] | 102 | } |
| 103 | |
David Majnemer | 0adde12 | 2011-06-14 05:17:32 +0000 | [diff] [blame] | 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 | |
| 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 | } |
Eli Friedman | 71b8fb5 | 2012-01-21 01:01:51 +0000 | [diff] [blame] | 121 | |
| 122 | int 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 | } |