diff options
author | Hans Wennborg <hans@hanshq.net> | 2011-10-18 08:10:06 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2011-10-18 08:10:06 +0000 |
commit | a7da2155167676a6a5d9fca4de947a9cab2a4908 (patch) | |
tree | 1e5ced027704a0e259308c93748e10eace432346 /test/Sema/format-strings-fixit.c | |
parent | 5f31f0893d75203c326ddcd9808099bbfe34aec0 (diff) |
Suggest %zu for size_t args to printf.
For PR11152. Make PrintSpecifier::fixType() suggest "%zu" for size_t, etc.
rather than looking at the underlying type and suggesting "%llu" or other
platform-specific length modifiers. Applies to C99 and C++11.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142342 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/format-strings-fixit.c')
-rw-r--r-- | test/Sema/format-strings-fixit.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/Sema/format-strings-fixit.c b/test/Sema/format-strings-fixit.c index d03cccb601..5b2f54a59f 100644 --- a/test/Sema/format-strings-fixit.c +++ b/test/Sema/format-strings-fixit.c @@ -46,6 +46,19 @@ void test() { // Perserve the original formatting for unsigned integers. unsigned long val = 42; printf("%X", val); + + typedef __SIZE_TYPE__ size_t; + typedef signed long int ssize_t; + typedef __INTMAX_TYPE__ intmax_t; + typedef __UINTMAX_TYPE__ uintmax_t; + typedef __PTRDIFF_TYPE__ ptrdiff_t; + + // size_t, etc. + printf("%c", (size_t) 42); + printf("%c", (ssize_t) 42); + printf("%c", (intmax_t) 42); + printf("%c", (uintmax_t) 42); + printf("%c", (ptrdiff_t) 42); } // Validate the fixes... @@ -68,3 +81,8 @@ void test() { // CHECK: printf("%s", "foo"); // CHECK: printf("%1$p", (void *)0); // CHECK: printf("%lX", val); +// CHECK: printf("%zu", (size_t) 42); +// CHECK: printf("%zd", (ssize_t) 42); +// CHECK: printf("%jd", (intmax_t) 42); +// CHECK: printf("%ju", (uintmax_t) 42); +// CHECK: printf("%td", (ptrdiff_t) 42); |