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
6 extern "C" int printf(const char *, ...);
7 #define LOG(...) printf(__VA_ARGS__)
17 using uint32_t = unsigned;
18 enum class FixedE
: uint32_t { Two
};
20 void a(N::E NEVal
, S
*SPtr
, S
&SRef
) {
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}:")"
25 printf("%hd", N::E::One
); // expected-warning{{format specifies type 'short' but the argument has type 'N::E'}}
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}:")"
30 printf("%hu", N::E::One
); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'N::E'}}
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}:")"
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}:")"
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}:")"
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}:")"
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}:")"
54 SPtr
->Type
// expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
56 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:7-[[@LINE-2]]:7}:"static_cast<int>("
57 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:17}:")"
59 LOG( // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
63 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:7-[[@LINE-2]]:7}:"static_cast<int>("
64 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:17}:")"
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}:")"
71 LOG("%d", // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
73 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:7}:"static_cast<int>("
74 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:")"
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}:")"