| 1 |
// RUN: %clang_cc1 -fsyntax-only -fblocks -verify -std=gnu11 -Wmissing-format-attribute %s |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -fblocks -verify -x c++ -std=gnu++98 -Wmissing-format-attribute %s |
| 3 |
// RUN: %clang_cc1 -fsyntax-only -fblocks -std=gnu11 -Wmissing-format-attribute -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s |
| 4 |
// RUN: %clang_cc1 -fsyntax-only -fblocks -x c++ -std=gnu++98 -Wmissing-format-attribute -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s |
| 5 |
|
| 6 |
typedef unsigned long size_t; |
| 7 |
typedef long ssize_t; |
| 8 |
typedef __builtin_va_list va_list; |
| 9 |
|
| 10 |
__attribute__((format(printf, 1, 2))) |
| 11 |
int printf(const char *, ...); |
| 12 |
|
| 13 |
__attribute__((format(printf, 1, 0))) |
| 14 |
int vprintf(const char *, va_list); |
| 15 |
|
| 16 |
// Test that attribute fixit is specified using the GNU extension format when -std=gnuXY or -std=gnu++XY. |
| 17 |
|
| 18 |
// CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:1-[[@LINE+1]]:1}:"__attribute__((format(printf, 1, 0))) " |
| 19 |
void f1(char *out, va_list args) // #f1 |
| 20 |
{ |
| 21 |
vprintf(out, args); // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 1, 0)' attribute to the declaration of 'f1'}} |
| 22 |
// expected-note@#f1 {{'f1' declared here}} |
| 23 |
} |
| 24 |
|
| 25 |
void f2(void) { |
| 26 |
void (^b1)(const char *, ...) = ^(const char *fmt, ...) { // #b1 |
| 27 |
va_list args; |
| 28 |
vprintf(fmt, args); // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 1, 2)' attribute to the declaration of block}} |
| 29 |
// expected-note@#b1 {{block declared here}} |
| 30 |
}; |
| 31 |
|
| 32 |
void (^b2)(const char *, va_list) = ^(const char *fmt, va_list args) { // #b2 |
| 33 |
vprintf(fmt, args); // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 1, 0)' attribute to the declaration of block}}. |
| 34 |
// expected-note@#b2 {{block declared here}} |
| 35 |
}; |
| 36 |
|
| 37 |
void (^b3)(const char *, int x, float y) = ^(const char *fmt, int x, float y) { // #b3 |
| 38 |
printf(fmt, x, y); // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 1, 2)' attribute to the declaration of block}}. |
| 39 |
// expected-note@#b3 {{block declared here}} |
| 40 |
}; |
| 41 |
|
| 42 |
void __attribute__((__format__(__printf__, 1, 2))) (^b4)(const char *, ...) = |
| 43 |
^(const char *fmt, ...) __attribute__((__format__(__printf__, 1, 2))) { |
| 44 |
va_list args; |
| 45 |
vprintf(fmt, args); |
| 46 |
}; |
| 47 |
|
| 48 |
void __attribute__((__format__(__printf__, 2, 3))) (^b5)(const char *, const char *, ...) = |
| 49 |
^(const char *not_fmt, const char *fmt, ...) __attribute__((__format__(__printf__, 2, 3))) { // #b5 |
| 50 |
va_list args; |
| 51 |
vprintf(fmt, args); |
| 52 |
vprintf(not_fmt, args); // expected-warning{{diagnostic behavior may be improved by adding the 'format(printf, 1, 3)' attribute to the declaration of block}} |
| 53 |
// expected-note@#b5 {{block declared here}} |
| 54 |
}; |
| 55 |
} |