Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wno-error=non-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 
     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 
     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 
     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 
     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 
     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:
     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 
     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 
     99 void t6(Foo somearg, ... ) {
    100   __builtin_va_list list;
    101   __builtin_va_start(list, somearg);
    102 }
    103 
    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 }
    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 }
    126 
    127 // PR14057
    128 namespace t10 {
    129   struct F {
    130     F();
    131   };
    132 
    133   struct S {
    134     void operator()(F, ...);
    135   };
    136 
    137   void foo() {
    138     S s;
    139     F f;
    140     s.operator()(f);
    141     s(f);
    142   }
    143 }
    144