annotate clang/test/SemaCXX/vararg-class.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -verify -Wclass-varargs -std=c++98 %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -verify -Wclass-varargs -std=c++11 %s
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 struct A {};
anatofuz
parents:
diff changeset
5 struct B { ~B(); };
anatofuz
parents:
diff changeset
6 class C { char *c_str(); };
anatofuz
parents:
diff changeset
7 struct D { char *c_str(); };
anatofuz
parents:
diff changeset
8 struct E { E(); };
anatofuz
parents:
diff changeset
9 struct F { F(); char *c_str(); };
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 void v(...);
anatofuz
parents:
diff changeset
12 void w(const char*, ...) __attribute__((format(printf, 1, 2)));
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 void test(A a, B b, C c, D d, E e, F f) {
anatofuz
parents:
diff changeset
15 v(a); // expected-warning-re {{passing object of class type 'A' through variadic function{{$}}}}
anatofuz
parents:
diff changeset
16 v(b); // expected-error-re {{cannot pass object of non-{{POD|trivial}} type 'B' through variadic function; call will abort at runtime}}
anatofuz
parents:
diff changeset
17 v(c); // expected-warning {{passing object of class type 'C' through variadic function; did you mean to call '.c_str()'?}}
anatofuz
parents:
diff changeset
18 v(d); // expected-warning {{passing object of class type 'D' through variadic function; did you mean to call '.c_str()'?}}
anatofuz
parents:
diff changeset
19 v(e);
anatofuz
parents:
diff changeset
20 v(f);
anatofuz
parents:
diff changeset
21 #if __cplusplus < 201103L
anatofuz
parents:
diff changeset
22 // expected-error@-3 {{cannot pass object of non-POD type 'E' through variadic function; call will abort at runtime}}
anatofuz
parents:
diff changeset
23 // expected-error@-3 {{cannot pass object of non-POD type 'F' through variadic function; call will abort at runtime}}
anatofuz
parents:
diff changeset
24 #else
anatofuz
parents:
diff changeset
25 // expected-warning-re@-6 {{passing object of class type 'E' through variadic function{{$}}}}
anatofuz
parents:
diff changeset
26 // expected-warning@-6 {{passing object of class type 'F' through variadic function; did you mean to call '.c_str()'?}}
anatofuz
parents:
diff changeset
27 #endif
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 v(d.c_str());
anatofuz
parents:
diff changeset
30 v(f.c_str());
anatofuz
parents:
diff changeset
31 v(0);
anatofuz
parents:
diff changeset
32 v('x');
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 w("%s", a); // expected-warning {{format specifies type 'char *' but the argument has type 'A'}}
anatofuz
parents:
diff changeset
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 *'}}
anatofuz
parents:
diff changeset
36 w("%s", c); // expected-warning {{format specifies type 'char *' but the argument has type 'C'}}
anatofuz
parents:
diff changeset
37 w("%s", d); // expected-warning {{format specifies type 'char *' but the argument has type 'D'}}
anatofuz
parents:
diff changeset
38 w("%s", e);
anatofuz
parents:
diff changeset
39 w("%s", f);
anatofuz
parents:
diff changeset
40 #if __cplusplus < 201103L
anatofuz
parents:
diff changeset
41 // expected-error@-3 {{cannot pass non-POD object of type 'E' to variadic function; expected type from format string was 'char *'}}
anatofuz
parents:
diff changeset
42 // expected-error@-3 {{cannot pass non-POD object of type 'F' to variadic function; expected type from format string was 'char *'}}
anatofuz
parents:
diff changeset
43 // expected-note@-4 {{did you mean to call the c_str() method?}}
anatofuz
parents:
diff changeset
44 #else
anatofuz
parents:
diff changeset
45 // expected-warning@-7 {{format specifies type 'char *' but the argument has type 'E'}}
anatofuz
parents:
diff changeset
46 // expected-warning@-7 {{format specifies type 'char *' but the argument has type 'F'}}
anatofuz
parents:
diff changeset
47 #endif
anatofuz
parents:
diff changeset
48 }