| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -std=c++11 %s |
| 2 |
|
| 3 |
extern "C" { |
| 4 |
extern int scanf(const char *restrict, ...); |
| 5 |
extern int printf(const char *restrict, ...); |
| 6 |
} |
| 7 |
|
| 8 |
void f(char **sp, float *fp) { |
| 9 |
scanf("%as", sp); // expected-warning{{format specifies type 'float *' but the argument has type 'char **'}} |
| 10 |
|
| 11 |
printf("%p", sp); // expected-warning{{format specifies type 'void *' but the argument has type 'char **'}} |
| 12 |
scanf("%p", sp); // expected-warning{{format specifies type 'void **' but the argument has type 'char **'}} |
| 13 |
|
| 14 |
printf("%a", 1.0); |
| 15 |
scanf("%afoobar", fp); |
| 16 |
printf(nullptr); |
| 17 |
// expected-warning@-1{{null passed to a callee that requires a non-null argument}} |
| 18 |
printf(*sp); // expected-warning {{not a string literal}} |
| 19 |
// expected-note@-1{{treat the string as an argument to avoid this}} |
| 20 |
|
| 21 |
// PR13099 |
| 22 |
printf( |
| 23 |
R"foobar(%)foobar" |
| 24 |
R"bazquux(d)bazquux" // expected-warning {{more '%' conversions than data arguments}} |
| 25 |
R"xyzzy()xyzzy"); |
| 26 |
|
| 27 |
printf(u8"this is %d test", 0); // ok |
| 28 |
printf(u8R"foo( |
| 29 |
\u1234\U0010fffe |
| 30 |
%d)foo" // expected-warning {{more '%' conversions than data arguments}} |
| 31 |
); |
| 32 |
|
| 33 |
printf("init list: %d", { 0 }); // expected-error {{cannot pass initializer list to variadic function; expected type from format string was 'int'}} |
| 34 |
printf("void: %d", f(sp, fp)); // expected-error {{cannot pass expression of type 'void' to variadic function; expected type from format string was 'int'}} |
| 35 |
printf(0, { 0 }); // expected-error {{cannot pass initializer list to variadic function}} |
| 36 |
// expected-warning@-1{{null passed to a callee that requires a non-null argument}} |
| 37 |
} |