2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wnon-pod-varargs
|
2009-01-13 13:48:52 +08:00
|
|
|
|
2009-01-17 00:48:51 +08:00
|
|
|
extern char version[];
|
|
|
|
|
2009-01-13 13:48:52 +08:00
|
|
|
class C {
|
|
|
|
public:
|
|
|
|
C(int);
|
|
|
|
void g(int a, ...);
|
|
|
|
static void h(int a, ...);
|
|
|
|
};
|
|
|
|
|
|
|
|
void g(int a, ...);
|
|
|
|
|
|
|
|
void t1()
|
|
|
|
{
|
|
|
|
C c(10);
|
|
|
|
|
2010-03-10 19:27:22 +08:00
|
|
|
g(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
|
2009-01-17 00:48:51 +08:00
|
|
|
g(10, version);
|
2009-01-13 13:48:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void t2()
|
|
|
|
{
|
|
|
|
C c(10);
|
|
|
|
|
2010-03-10 19:27:22 +08:00
|
|
|
c.g(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
|
2009-01-17 00:48:51 +08:00
|
|
|
c.g(10, version);
|
2009-01-13 13:48:52 +08:00
|
|
|
|
2010-03-10 19:27:22 +08:00
|
|
|
C::h(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic function; call will abort at runtime}}
|
2009-01-17 00:48:51 +08:00
|
|
|
C::h(10, version);
|
2009-01-13 13:48:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int (^block)(int, ...);
|
|
|
|
|
|
|
|
void t3()
|
|
|
|
{
|
|
|
|
C c(10);
|
|
|
|
|
2010-03-10 19:27:22 +08:00
|
|
|
block(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic block; call will abort at runtime}}
|
2009-01-17 00:48:51 +08:00
|
|
|
block(10, version);
|
2009-01-13 13:48:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class D {
|
|
|
|
public:
|
|
|
|
void operator() (int a, ...);
|
|
|
|
};
|
|
|
|
|
|
|
|
void t4()
|
|
|
|
{
|
|
|
|
C c(10);
|
|
|
|
|
|
|
|
D d;
|
|
|
|
|
2010-03-10 19:27:22 +08:00
|
|
|
d(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic method; call will abort at runtime}}
|
2009-01-17 00:48:51 +08:00
|
|
|
d(10, version);
|
2009-01-13 13:48:52 +08:00
|
|
|
}
|
2009-09-08 09:48:42 +08:00
|
|
|
|
|
|
|
class E {
|
2011-05-22 03:26:31 +08:00
|
|
|
E(int, ...); // expected-note 2{{implicitly declared private here}}
|
2009-09-08 09:48:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void t5()
|
|
|
|
{
|
|
|
|
C c(10);
|
|
|
|
|
2011-05-22 03:26:31 +08:00
|
|
|
E e(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}} \
|
|
|
|
// expected-error{{calling a private constructor of class 'E'}}
|
|
|
|
(void)E(10, c); // expected-warning{{cannot pass object of non-POD type 'C' through variadic constructor; call will abort at runtime}} \
|
|
|
|
// expected-error{{calling a private constructor of class 'E'}}
|
|
|
|
|
2009-11-08 09:45:36 +08:00
|
|
|
}
|
2009-12-12 15:25:49 +08:00
|
|
|
|
|
|
|
// PR5761: unevaluated operands and the non-POD warning
|
|
|
|
class Foo {
|
|
|
|
public:
|
|
|
|
Foo() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
int Helper(...);
|
|
|
|
const int size = sizeof(Helper(Foo()));
|
2009-12-12 15:57:52 +08:00
|
|
|
|
|
|
|
namespace std {
|
|
|
|
class type_info { };
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Base { virtual ~Base(); };
|
|
|
|
Base &get_base(...);
|
|
|
|
int eat_base(...);
|
|
|
|
|
|
|
|
void test_typeid(Base &base) {
|
2012-01-17 09:17:46 +08:00
|
|
|
(void)typeid(get_base(base)); // expected-warning{{cannot pass object of non-POD type 'Base' through variadic function; call will abort at runtime}} \
|
|
|
|
// expected-error {{potentially evaluatable, but not obviously potentially evaluatable}}
|
2009-12-12 15:57:52 +08:00
|
|
|
(void)typeid(eat_base(base)); // okay
|
|
|
|
}
|
2010-05-16 12:01:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
// rdar://7985267 - Shouldn't warn, doesn't actually use __builtin_va_start is
|
|
|
|
// magic.
|
|
|
|
|
|
|
|
void t6(Foo somearg, ... ) {
|
2010-05-16 13:00:34 +08:00
|
|
|
__builtin_va_list list;
|
|
|
|
__builtin_va_start(list, somearg);
|
2010-05-16 12:01:30 +08:00
|
|
|
}
|
|
|
|
|
2011-06-14 13:17:32 +08:00
|
|
|
void t7(int n, ...) {
|
|
|
|
__builtin_va_list list;
|
|
|
|
__builtin_va_start(list, n);
|
|
|
|
(void)__builtin_va_arg(list, C); // expected-warning{{second argument to 'va_arg' is of non-POD type 'C'}}
|
|
|
|
__builtin_va_end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Abstract {
|
|
|
|
virtual void doit() = 0; // expected-note{{unimplemented pure virtual method}}
|
|
|
|
};
|
|
|
|
|
|
|
|
void t8(int n, ...) {
|
|
|
|
__builtin_va_list list;
|
|
|
|
__builtin_va_start(list, n);
|
|
|
|
(void)__builtin_va_arg(list, Abstract); // expected-error{{second argument to 'va_arg' is of abstract type 'Abstract'}}
|
|
|
|
__builtin_va_end(list);
|
|
|
|
}
|