49 lines · cpp
1// RUN: %clang_cc1 -verify -Wclass-varargs -std=c++98 %s2// RUN: %clang_cc1 -verify -Wclass-varargs -std=c++11 %s3 4struct A {};5struct B { ~B(); };6class C { char *c_str(); };7struct D { char *c_str(); };8struct E { E(); };9struct F { F(); char *c_str(); };10 11void v(...);12void w(const char*, ...) __attribute__((format(printf, 1, 2)));13 14void test(A a, B b, C c, D d, E e, F f) {15 v(a); // expected-warning-re {{passing object of class type 'A' through variadic function{{$}}}}16 v(b); // expected-error-re {{cannot pass object of non-{{POD|trivial}} type 'B' through variadic function; call will abort at runtime}}17 v(c); // expected-warning {{passing object of class type 'C' through variadic function; did you mean to call '.c_str()'?}}18 v(d); // expected-warning {{passing object of class type 'D' through variadic function; did you mean to call '.c_str()'?}}19 v(e);20 v(f);21#if __cplusplus < 201103L22 // expected-error@-3 {{cannot pass object of non-POD type 'E' through variadic function; call will abort at runtime}}23 // expected-error@-3 {{cannot pass object of non-POD type 'F' through variadic function; call will abort at runtime}}24#else25 // expected-warning-re@-6 {{passing object of class type 'E' through variadic function{{$}}}}26 // expected-warning@-6 {{passing object of class type 'F' through variadic function; did you mean to call '.c_str()'?}}27#endif28 29 v(d.c_str());30 v(f.c_str());31 v(0);32 v('x');33 34 w("%s", a); // expected-warning {{format specifies type 'char *' but the argument has type 'A'}}35 w("%s", b); // expected-error-re {{cannot pass non-{{POD|trivial}} object of type 'B' to variadic function; expected type from format string was 'char *'}}36 w("%s", c); // expected-warning {{format specifies type 'char *' but the argument has type 'C'}}37 w("%s", d); // expected-warning {{format specifies type 'char *' but the argument has type 'D'}}38 w("%s", e);39 w("%s", f);40#if __cplusplus < 201103L41 // expected-error@-3 {{cannot pass non-POD object of type 'E' to variadic function; expected type from format string was 'char *'}}42 // expected-error@-3 {{cannot pass non-POD object of type 'F' to variadic function; expected type from format string was 'char *'}}43 // expected-note@-4 {{did you mean to call the c_str() method?}}44#else45 // expected-warning@-7 {{format specifies type 'char *' but the argument has type 'E'}}46 // expected-warning@-7 {{format specifies type 'char *' but the argument has type 'F'}}47#endif48}49