|
| 1 | +// RUN: %clang_cc1 -fsyntax-only -verify -Wformat %s |
1 | 2 | // RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -Wformat %s 2>&1 | FileCheck %s
|
2 | 3 |
|
3 | 4 | extern "C" int printf(const char *, ...);
|
| 5 | +#define LOG(...) printf(__VA_ARGS__) |
4 | 6 |
|
5 | 7 | namespace N {
|
6 | 8 | enum class E { One };
|
7 | 9 | }
|
8 | 10 |
|
9 |
| -void a() { |
| 11 | +struct S { |
| 12 | + N::E Type; |
| 13 | +}; |
| 14 | + |
| 15 | +void a(N::E NEVal, S *SPtr, S &SRef) { |
10 | 16 | printf("%d", N::E::One); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
|
11 | 17 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"static_cast<int>("
|
12 | 18 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:25-[[@LINE-2]]:25}:")"
|
13 | 19 |
|
14 |
| - printf("%hd", N::E::One); |
| 20 | + printf("%hd", N::E::One); // expected-warning{{format specifies type 'short' but the argument has type 'N::E'}} |
15 | 21 | // CHECK: "static_cast<short>("
|
16 | 22 |
|
17 |
| - printf("%hu", N::E::One); |
| 23 | + printf("%hu", N::E::One); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'N::E'}} |
18 | 24 | // CHECK: "static_cast<unsigned short>("
|
| 25 | + |
| 26 | + LOG("%d", N::E::One); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 27 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:"static_cast<int>(" |
| 28 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:22-[[@LINE-2]]:22}:")" |
| 29 | + |
| 30 | + printf("%d", NEVal); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 31 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"static_cast<int>(" |
| 32 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:21-[[@LINE-2]]:21}:")" |
| 33 | + |
| 34 | + LOG("%d", NEVal); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 35 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:"static_cast<int>(" |
| 36 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:18-[[@LINE-2]]:18}:")" |
| 37 | + |
| 38 | + printf( |
| 39 | + "%d", |
| 40 | + SPtr->Type // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 41 | + ); |
| 42 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:7-[[@LINE-2]]:7}:"static_cast<int>(" |
| 43 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:17}:")" |
| 44 | + |
| 45 | + LOG( // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 46 | + "%d", |
| 47 | + SPtr->Type |
| 48 | + ); |
| 49 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:7-[[@LINE-2]]:7}:"static_cast<int>(" |
| 50 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:17}:")" |
| 51 | + |
| 52 | + printf("%d", |
| 53 | + SRef.Type); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 54 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:7}:"static_cast<int>(" |
| 55 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:")" |
| 56 | + |
| 57 | + LOG("%d", // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 58 | + SRef.Type); |
| 59 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:7}:"static_cast<int>(" |
| 60 | + // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:")" |
19 | 61 | }
|
0 commit comments