format-strings-int-typedefs.c 1.8 KB

123456789101112131415161718192021222324252627
  1. // RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
  2. int printf(char const *, ...);
  3. void test(void) {
  4. printf("%jd", 42.0); // expected-warning {{conversion specifies type 'intmax_t' (aka 'long long')}}
  5. printf("%ju", 42.0); // expected-warning {{conversion specifies type 'uintmax_t' (aka 'unsigned long long')}}
  6. printf("%zu", 42.0); // expected-warning {{conversion specifies type 'size_t' (aka 'unsigned long')}}
  7. printf("%td", 42.0); // expected-warning {{conversion specifies type 'ptrdiff_t' (aka 'int')}}
  8. printf("%lc", 42.0); // expected-warning {{conversion specifies type 'wint_t' (aka 'int')}}
  9. printf("%ls", 42.0); // expected-warning {{conversion specifies type 'wchar_t *' (aka 'int *')}}
  10. printf("%S", 42.0); // expected-warning {{conversion specifies type 'wchar_t *' (aka 'int *')}}
  11. printf("%C", 42.0); // expected-warning {{conversion specifies type 'wchar_t' (aka 'int')}}
  12. // typedef size_t et al. to something crazy.
  13. typedef void *size_t;
  14. typedef void *intmax_t;
  15. typedef void *uintmax_t;
  16. typedef void *ptrdiff_t;
  17. // The warning still fires, because it checks the underlying type.
  18. printf("%jd", (intmax_t)42); // expected-warning {{conversion specifies type 'intmax_t' (aka 'long long') but the argument has type 'intmax_t' (aka 'void *')}}
  19. 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 *')}}
  20. printf("%zu", (size_t)42); // expected-warning {{conversion specifies type 'size_t' (aka 'unsigned long') but the argument has type 'size_t' (aka 'void *')}}
  21. printf("%td", (ptrdiff_t)42); // expected-warning {{conversion specifies type 'ptrdiff_t' (aka 'int') but the argument has type 'ptrdiff_t' (aka 'void *')}}
  22. }