aboutsummaryrefslogtreecommitdiff
path: root/test/Sema/format-strings-int-typedefs.c
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2011-12-07 10:33:11 +0000
committerHans Wennborg <hans@hanshq.net>2011-12-07 10:33:11 +0000
commita792aff1c7de253b89c473fdb7eef4a5bba83aec (patch)
tree861496c88b07bf5ca7eca8921971bf02e6b7fdb8 /test/Sema/format-strings-int-typedefs.c
parent29f2787b6da552018a7716f18f5bd8f67bd6edb5 (diff)
Make printf warnings refer to intmax_t et al. by name
in addition to underlying type. For example, the warning for printf("%zu", 42.0); changes from "conversion specifies type 'unsigned long'" to "conversion specifies type 'size_t' (aka 'unsigned long')" (This is a second attempt after r145697, which got reverted.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146032 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/format-strings-int-typedefs.c')
-rw-r--r--test/Sema/format-strings-int-typedefs.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/Sema/format-strings-int-typedefs.c b/test/Sema/format-strings-int-typedefs.c
new file mode 100644
index 0000000000..29565e69ad
--- /dev/null
+++ b/test/Sema/format-strings-int-typedefs.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+
+int printf(char const *, ...);
+
+void test(void) {
+ printf("%jd", 42.0); // expected-warning {{conversion specifies type 'intmax_t' (aka 'long long')}}
+ printf("%ju", 42.0); // expected-warning {{conversion specifies type 'uintmax_t' (aka 'unsigned long long')}}
+ printf("%zu", 42.0); // expected-warning {{conversion specifies type 'size_t' (aka 'unsigned long')}}
+ printf("%td", 42.0); // expected-warning {{conversion specifies type 'ptrdiff_t' (aka 'int')}}
+
+ // typedef size_t et al. to something crazy.
+ typedef void *size_t;
+ typedef void *intmax_t;
+ typedef void *uintmax_t;
+ typedef void *ptrdiff_t;
+
+ // The warning still fires, because it checks the underlying type.
+ printf("%jd", (intmax_t)42); // expected-warning {{conversion specifies type 'intmax_t' (aka 'long long') but the argument has type 'intmax_t' (aka 'void *')}}
+ printf("%ju", (uintmax_t)42); // expected-warning {{conversion specifies type 'uintmax_t' (aka 'unsigned long long') but the argument has type 'uintmax_t' (aka 'void *')}}
+ printf("%zu", (size_t)42); // expected-warning {{conversion specifies type 'size_t' (aka 'unsigned long') but the argument has type 'size_t' (aka 'void *')}}
+ printf("%td", (ptrdiff_t)42); // expected-warning {{conversion specifies type 'ptrdiff_t' (aka 'int') but the argument has type 'ptrdiff_t' (aka 'void *')}}
+}