|
| 1 | +// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -Wformat-non-iso -fblocks -std=c++11 %s |
| 2 | + |
| 3 | +__attribute__((format(scanf, 1, 2))) |
| 4 | +int scanf(const char *, ...); |
| 5 | + |
| 6 | +template<typename... Args> |
| 7 | +__attribute__((format(scanf, 1, 2))) |
| 8 | +int scan(const char *fmt, Args &&...args) { // expected-warning{{GCC requires a function with the 'format' attribute to be variadic}} |
| 9 | + return scanf(fmt, args...); |
| 10 | +} |
| 11 | + |
| 12 | +union bag { |
| 13 | + bool b; |
| 14 | + unsigned char uc; |
| 15 | + signed char sc; |
| 16 | + unsigned short us; |
| 17 | + signed short ss; |
| 18 | + unsigned int ui; |
| 19 | + signed int si; |
| 20 | + unsigned long ul; |
| 21 | + signed long sl; |
| 22 | + unsigned long long ull; |
| 23 | + signed long long sll; |
| 24 | + __fp16 f16; |
| 25 | + float ff; |
| 26 | + double fd; |
| 27 | + long double fl; |
| 28 | +}; |
| 29 | + |
| 30 | +void test(void) { |
| 31 | + bag b; |
| 32 | + scan("%hhi %hhu %hhi %hhu", &b.sc, &b.uc, &b.b, &b.b); |
| 33 | + scan("%hi %hu", &b.ss, &b.us); |
| 34 | + scan("%i %u", &b.si, &b.ui); |
| 35 | + scan("%li %lu", &b.sl, &b.ul); |
| 36 | + scan("%lli %llu", &b.sll, &b.ull); |
| 37 | + scan("%f", &b.ff); |
| 38 | + scan("%lf", &b.fd); |
| 39 | + scan("%Lf", &b.fl); |
| 40 | + |
| 41 | + // expected-warning@+4{{format specifies type 'short *' but the argument has type 'signed char *'}} |
| 42 | + // expected-warning@+3{{format specifies type 'unsigned short *' but the argument has type 'unsigned char *'}} |
| 43 | + // expected-warning@+2{{format specifies type 'short *' but the argument has type 'bool *'}} |
| 44 | + // expected-warning@+1{{format specifies type 'unsigned short *' but the argument has type 'bool *'}} |
| 45 | + scan("%hi %hu %hi %hu", &b.sc, &b.uc, &b.b, &b.b); |
| 46 | + |
| 47 | + // expected-warning@+3{{format specifies type 'long *' but the argument has type 'short *'}} |
| 48 | + // expected-warning@+2{{format specifies type 'char *' but the argument has type 'short *'}} |
| 49 | + // expected-warning@+1{{format specifies type 'int *' but the argument has type 'short *'}} |
| 50 | + scan("%hhi %i %li", &b.ss, &b.ss, &b.ss); |
| 51 | + |
| 52 | + // expected-warning@+3{{format specifies type 'float *' but the argument has type '__fp16 *'}} |
| 53 | + // expected-warning@+2{{format specifies type 'float *' but the argument has type 'double *'}} |
| 54 | + // expected-warning@+1{{format specifies type 'float *' but the argument has type 'long double *'}} |
| 55 | + scan("%f %f %f", &b.f16, &b.fd, &b.fl); |
| 56 | + |
| 57 | + // expected-warning@+3{{format specifies type 'double *' but the argument has type '__fp16 *'}} |
| 58 | + // expected-warning@+2{{format specifies type 'double *' but the argument has type 'float *'}} |
| 59 | + // expected-warning@+1{{format specifies type 'double *' but the argument has type 'long double *'}} |
| 60 | + scan("%lf %lf %lf", &b.f16, &b.ff, &b.fl); |
| 61 | + |
| 62 | + // expected-warning@+3{{format specifies type 'long double *' but the argument has type '__fp16 *'}} |
| 63 | + // expected-warning@+2{{format specifies type 'long double *' but the argument has type 'float *'}} |
| 64 | + // expected-warning@+1{{format specifies type 'long double *' but the argument has type 'double *'}} |
| 65 | + scan("%Lf %Lf %Lf", &b.f16, &b.ff, &b.fd); |
| 66 | +} |
0 commit comments