ZijunZhaoCCK | 73ed215 | 2024-04-22 10:17:12 -0700 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wformat-pedantic %s |
| 2 | // RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -Wformat-pedantic %s 2>&1 | FileCheck %s |
| 3 | // RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -Wformat %s -verify=okay |
| 4 | // okay-no-diagnostics |
Alex Brachet | 563a23c | 2023-07-14 16:23:22 +0000 | [diff] [blame] | 5 | |
| 6 | extern "C" int printf(const char *, ...); |
Shoaib Meenai | 61c5ad8 | 2023-09-20 17:32:35 -0700 | [diff] [blame] | 7 | #define LOG(...) printf(__VA_ARGS__) |
Alex Brachet | 563a23c | 2023-07-14 16:23:22 +0000 | [diff] [blame] | 8 | |
| 9 | namespace N { |
| 10 | enum class E { One }; |
| 11 | } |
| 12 | |
Shoaib Meenai | 61c5ad8 | 2023-09-20 17:32:35 -0700 | [diff] [blame] | 13 | struct S { |
| 14 | N::E Type; |
| 15 | }; |
| 16 | |
Shoaib Meenai | 0b07b06 | 2023-10-02 11:32:54 -0700 | [diff] [blame] | 17 | using uint32_t = unsigned; |
| 18 | enum class FixedE : uint32_t { Two }; |
| 19 | |
Shoaib Meenai | 61c5ad8 | 2023-09-20 17:32:35 -0700 | [diff] [blame] | 20 | void a(N::E NEVal, S *SPtr, S &SRef) { |
Alex Brachet | 563a23c | 2023-07-14 16:23:22 +0000 | [diff] [blame] | 21 | printf("%d", N::E::One); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 22 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"static_cast<int>(" |
| 23 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:25-[[@LINE-2]]:25}:")" |
| 24 | |
Shoaib Meenai | 61c5ad8 | 2023-09-20 17:32:35 -0700 | [diff] [blame] | 25 | printf("%hd", N::E::One); // expected-warning{{format specifies type 'short' but the argument has type 'N::E'}} |
Shoaib Meenai | 0b07b06 | 2023-10-02 11:32:54 -0700 | [diff] [blame] | 26 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%d" |
| 27 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:17-[[@LINE-2]]:17}:"static_cast<int>(" |
| 28 | // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:26-[[@LINE-3]]:26}:")" |
Alex Brachet | 563a23c | 2023-07-14 16:23:22 +0000 | [diff] [blame] | 29 | |
Shoaib Meenai | 61c5ad8 | 2023-09-20 17:32:35 -0700 | [diff] [blame] | 30 | printf("%hu", N::E::One); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'N::E'}} |
Shoaib Meenai | 0b07b06 | 2023-10-02 11:32:54 -0700 | [diff] [blame] | 31 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%d" |
| 32 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:17-[[@LINE-2]]:17}:"static_cast<int>(" |
| 33 | // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:26-[[@LINE-3]]:26}:")" |
Shoaib Meenai | 61c5ad8 | 2023-09-20 17:32:35 -0700 | [diff] [blame] | 34 | |
| 35 | LOG("%d", N::E::One); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 36 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:"static_cast<int>(" |
| 37 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:22-[[@LINE-2]]:22}:")" |
| 38 | |
Shoaib Meenai | 0b07b06 | 2023-10-02 11:32:54 -0700 | [diff] [blame] | 39 | LOG("%s", N::E::One); // expected-warning{{format specifies type 'char *' but the argument has type 'N::E'}} |
| 40 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:8-[[@LINE-1]]:10}:"%d" |
| 41 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:13}:"static_cast<int>(" |
| 42 | // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:")" |
| 43 | |
Shoaib Meenai | 61c5ad8 | 2023-09-20 17:32:35 -0700 | [diff] [blame] | 44 | printf("%d", NEVal); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 45 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"static_cast<int>(" |
| 46 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:21-[[@LINE-2]]:21}:")" |
| 47 | |
| 48 | LOG("%d", NEVal); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 49 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:"static_cast<int>(" |
| 50 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:18-[[@LINE-2]]:18}:")" |
| 51 | |
| 52 | printf( |
| 53 | "%d", |
| 54 | SPtr->Type // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 55 | ); |
| 56 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:7-[[@LINE-2]]:7}:"static_cast<int>(" |
| 57 | // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:17}:")" |
| 58 | |
| 59 | LOG( // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 60 | "%d", |
| 61 | SPtr->Type |
| 62 | ); |
| 63 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:7-[[@LINE-2]]:7}:"static_cast<int>(" |
| 64 | // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:17}:")" |
| 65 | |
| 66 | printf("%d", |
| 67 | SRef.Type); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 68 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:7}:"static_cast<int>(" |
| 69 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:")" |
| 70 | |
| 71 | LOG("%d", // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}} |
| 72 | SRef.Type); |
| 73 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:7}:"static_cast<int>(" |
| 74 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:")" |
Shoaib Meenai | 0b07b06 | 2023-10-02 11:32:54 -0700 | [diff] [blame] | 75 | |
| 76 | printf("%u", FixedE::Two); //expected-warning{{format specifies type 'unsigned int' but the argument has type 'FixedE'}} |
| 77 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"static_cast<uint32_t>(" |
| 78 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:27-[[@LINE-2]]:27}:")" |
Alex Brachet | 563a23c | 2023-07-14 16:23:22 +0000 | [diff] [blame] | 79 | } |