mirror of
https://github.com/intel/llvm.git
synced 2026-01-15 12:25:46 +08:00
This helps transition code bases to handle the new warning added in 3632e2f517
Before:
```
clang/test/FixIt/format.cpp:10:16: warning: format specifies type 'int' but the argument has type 'N::E' [-Wformat]
10 | printf("%d", N::E::One); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
| ~~ ^~~~~~~~~
| %d
```
After:
```
clang/test/FixIt/format.cpp:10:16: warning: format specifies type 'int' but the argument has type 'N::E' [-Wformat]
10 | printf("%d", N::E::One); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
| ~~ ^~~~~~~~~
| static_cast<int>( )
```
Differential Revision: https://reviews.llvm.org/D153623
20 lines
584 B
C++
20 lines
584 B
C++
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -Wformat %s 2>&1 | FileCheck %s
|
|
|
|
extern "C" int printf(const char *, ...);
|
|
|
|
namespace N {
|
|
enum class E { One };
|
|
}
|
|
|
|
void a() {
|
|
printf("%d", N::E::One); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"static_cast<int>("
|
|
// CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:25-[[@LINE-2]]:25}:")"
|
|
|
|
printf("%hd", N::E::One);
|
|
// CHECK: "static_cast<short>("
|
|
|
|
printf("%hu", N::E::One);
|
|
// CHECK: "static_cast<unsigned short>("
|
|
}
|