| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++23 -Wmissing-format-attribute %s |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -Wmissing-format-attribute -fdiagnostics-parseable-fixits -std=c++23 %s 2>&1 | FileCheck %s |
| 3 |
|
| 4 |
typedef __SIZE_TYPE__ size_t; |
| 5 |
typedef __builtin_va_list va_list; |
| 6 |
|
| 7 |
[[gnu::format(printf, 1, 2)]] |
| 8 |
int printf(const char *, ...); |
| 9 |
|
| 10 |
[[gnu::format(scanf, 1, 2)]] |
| 11 |
int scanf(const char *, ...); |
| 12 |
|
| 13 |
[[gnu::format(printf, 1, 0)]] |
| 14 |
int vprintf(const char *, va_list); |
| 15 |
|
| 16 |
[[gnu::format(scanf, 1, 0)]] |
| 17 |
int vscanf(const char *, va_list); |
| 18 |
|
| 19 |
[[gnu::format(printf, 2, 0)]] |
| 20 |
int vsprintf(char *, const char *, va_list); |
| 21 |
|
| 22 |
[[gnu::format(printf, 3, 0)]] |
| 23 |
int vsnprintf(char *, size_t, const char *, va_list); |
| 24 |
|
| 25 |
struct S1 |
| 26 |
{ |
| 27 |
// CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:3-[[@LINE+1]]:3}:"{{\[\[}}gnu::format(scanf, 2, 3)]] " |
| 28 |
void fn1(const char *out, ... /* args */) // #S1_fn1 |
| 29 |
{ |
| 30 |
va_list args; |
| 31 |
vscanf(out, args); // expected-warning {{diagnostic behavior may be improved by adding the 'format(scanf, 2, 3)' attribute to the declaration of 'fn1'}} |
| 32 |
// expected-note@#S1_fn1 {{'fn1' declared here}} |
| 33 |
} |
| 34 |
|
| 35 |
[[gnu::format(printf, 2, 0)]] |
| 36 |
void print(const char *out, va_list args); |
| 37 |
|
| 38 |
// CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:3-[[@LINE+1]]:3}:"{{\[\[}}gnu::format(printf, 2, 3)]] " |
| 39 |
void fn2(const char *out, ... /* args */) // #S1_fn2 |
| 40 |
{ |
| 41 |
va_list args; |
| 42 |
print(out, args); // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 2, 3)' attribute to the declaration of 'fn2'}} |
| 43 |
// expected-note@#S1_fn2 {{'fn2' declared here}} |
| 44 |
} |
| 45 |
|
| 46 |
// CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:3-[[@LINE+1]]:3}:"{{\[\[}}gnu::format(printf, 2, 0)]] " |
| 47 |
void fn3(const char *out, va_list args) // #S1_fn3 |
| 48 |
{ |
| 49 |
print(out, args); // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 2, 0)' attribute to the declaration of 'fn3'}} |
| 50 |
// expected-note@#S1_fn3 {{'fn3' declared here}} |
| 51 |
} |
| 52 |
|
| 53 |
// CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:3-[[@LINE+1]]:3}:"{{\[\[}}gnu::format(printf, 2, 3)]] " |
| 54 |
void fn4(this S1& self, const char *out, ... /* args */) // #S1_fn4 |
| 55 |
{ |
| 56 |
va_list args; |
| 57 |
self.print(out, args); // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 2, 3)' attribute to the declaration of 'fn4'}} |
| 58 |
// expected-note@#S1_fn4 {{'fn4' declared here}} |
| 59 |
} |
| 60 |
|
| 61 |
// CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:3-[[@LINE+1]]:3}:"{{\[\[}}gnu::format(printf, 2, 0)]] " |
| 62 |
void fn5(this S1& self, const char *out, va_list args) // #S1_fn5 |
| 63 |
{ |
| 64 |
self.print(out, args); // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 2, 0)' attribute to the declaration of 'fn5'}} |
| 65 |
// expected-note@#S1_fn5 {{'fn5' declared here}} |
| 66 |
} |
| 67 |
}; |
| 68 |
|