Skip to content

Commit 2ca4686

Browse files
committed
Add an inttypes.h wrapper that fixes up some macros in Microsoft mode.
Before MSVS2015, MSVS's headers disagree about int32_t and PRIx32 and so on. Provide a wrapper header to fix this, so that -Wformat can still be used. Fixes PR23412. llvm-svn: 240741
1 parent 4f9dee7 commit 2ca4686

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

clang/lib/Headers/inttypes.h

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*===---- inttypes.h - Standard header for integer printf macros ----------===*\
2+
*
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to deal
5+
* in the Software without restriction, including without limitation the rights
6+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
* copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
* THE SOFTWARE.
20+
*
21+
\*===----------------------------------------------------------------------===*/
22+
23+
#ifndef __CLANG_INTTYPES_H
24+
#define __CLANG_INTTYPES_H
25+
26+
#include_next <inttypes.h>
27+
28+
#if defined(_MSC_VER) && _MSC_VER < 1900
29+
/* MSVC headers define int32_t as int, but PRIx32 as "lx" instead of "x".
30+
* This triggers format warnings, so fix it up here. */
31+
#undef PRId32
32+
#undef PRIdLEAST32
33+
#undef PRIdFAST32
34+
#undef PRIi32
35+
#undef PRIiLEAST32
36+
#undef PRIiFAST32
37+
#undef PRIo32
38+
#undef PRIoLEAST32
39+
#undef PRIoFAST32
40+
#undef PRIu32
41+
#undef PRIuLEAST32
42+
#undef PRIuFAST32
43+
#undef PRIx32
44+
#undef PRIxLEAST32
45+
#undef PRIxFAST32
46+
#undef PRIX32
47+
#undef PRIXLEAST32
48+
#undef PRIXFAST32
49+
50+
#undef SCNd32
51+
#undef SCNdLEAST32
52+
#undef SCNdFAST32
53+
#undef SCNi32
54+
#undef SCNiLEAST32
55+
#undef SCNiFAST32
56+
#undef SCNo32
57+
#undef SCNoLEAST32
58+
#undef SCNoFAST32
59+
#undef SCNu32
60+
#undef SCNuLEAST32
61+
#undef SCNuFAST32
62+
#undef SCNx32
63+
#undef SCNxLEAST32
64+
#undef SCNxFAST32
65+
66+
#define PRId32 "d"
67+
#define PRIdLEAST32 "d"
68+
#define PRIdFAST32 "d"
69+
#define PRIi32 "i"
70+
#define PRIiLEAST32 "i"
71+
#define PRIiFAST32 "i"
72+
#define PRIo32 "o"
73+
#define PRIoLEAST32 "o"
74+
#define PRIoFAST32 "o"
75+
#define PRIu32 "u"
76+
#define PRIuLEAST32 "u"
77+
#define PRIuFAST32 "u"
78+
#define PRIx32 "x"
79+
#define PRIxLEAST32 "x"
80+
#define PRIxFAST32 "x"
81+
#define PRIX32 "X"
82+
#define PRIXLEAST32 "X"
83+
#define PRIXFAST32 "X"
84+
85+
#define SCNd32 "d"
86+
#define SCNdLEAST32 "d"
87+
#define SCNdFAST32 "d"
88+
#define SCNi32 "i"
89+
#define SCNiLEAST32 "i"
90+
#define SCNiFAST32 "i"
91+
#define SCNo32 "o"
92+
#define SCNoLEAST32 "o"
93+
#define SCNoFAST32 "o"
94+
#define SCNu32 "u"
95+
#define SCNuLEAST32 "u"
96+
#define SCNuFAST32 "u"
97+
#define SCNx32 "x"
98+
#define SCNxLEAST32 "x"
99+
#define SCNxFAST32 "x"
100+
#endif
101+
102+
#endif /* __CLANG_INTTYPES_H */

0 commit comments

Comments
 (0)