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