1 // RUN: %clang_cc1 -fsyntax-only -verify -Wformat %s
2 // RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -Wformat %s 2>&1 | FileCheck %s
4 extern "C" int printf(const char *, ...);
5 #define LOG(...) printf(__VA_ARGS__)
15 using uint32_t = unsigned;
16 enum class FixedE
: uint32_t { Two
};
18 void a(N::E NEVal
, S
*SPtr
, S
&SRef
) {
19 printf("%d", N::E::One
); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
20 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"static_cast<int>("
21 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:25-[[@LINE-2]]:25}:")"
23 printf("%hd", N::E::One
); // expected-warning{{format specifies type 'short' but the argument has type 'N::E'}}
24 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%d"
25 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:17-[[@LINE-2]]:17}:"static_cast<int>("
26 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:26-[[@LINE-3]]:26}:")"
28 printf("%hu", N::E::One
); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'N::E'}}
29 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%d"
30 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:17-[[@LINE-2]]:17}:"static_cast<int>("
31 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:26-[[@LINE-3]]:26}:")"
33 LOG("%d", N::E::One
); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
34 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:"static_cast<int>("
35 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:22-[[@LINE-2]]:22}:")"
37 LOG("%s", N::E::One
); // expected-warning{{format specifies type 'char *' but the argument has type 'N::E'}}
38 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:8-[[@LINE-1]]:10}:"%d"
39 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:13}:"static_cast<int>("
40 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:22-[[@LINE-3]]:22}:")"
42 printf("%d", NEVal
); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
43 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"static_cast<int>("
44 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:21-[[@LINE-2]]:21}:")"
46 LOG("%d", NEVal
); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
47 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:"static_cast<int>("
48 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:18-[[@LINE-2]]:18}:")"
52 SPtr
->Type
// expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
54 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:7-[[@LINE-2]]:7}:"static_cast<int>("
55 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:17}:")"
57 LOG( // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
61 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:7-[[@LINE-2]]:7}:"static_cast<int>("
62 // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:17}:")"
65 SRef
.Type
); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
66 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:7}:"static_cast<int>("
67 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:")"
69 LOG("%d", // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
71 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:7}:"static_cast<int>("
72 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:")"
74 printf("%u", FixedE::Two
); //expected-warning{{format specifies type 'unsigned int' but the argument has type 'FixedE'}}
75 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"static_cast<uint32_t>("
76 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:27-[[@LINE-2]]:27}:")"