1 // RUN: %clang_cc1 -verify -Wclass-varargs -std=c++98 %s
2 // RUN: %clang_cc1 -verify -Wclass-varargs -std=c++11 %s
6 class C
{ char *c_str(); };
7 struct D
{ char *c_str(); };
9 struct F
{ F(); char *c_str(); };
12 void w(const char*, ...) __attribute__((format(printf
, 1, 2)));
14 void 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()'?}}
21 #if __cplusplus < 201103L
22 // 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}}
25 // 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()'?}}
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'}}
40 #if __cplusplus < 201103L
41 // 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?}}
45 // 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'}}