format-strings-c90.c 1.4 KB

123456789101112131415161718192021222324252627282930
  1. /* RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin9 -Wformat-non-iso -std=c89 %s
  2. */
  3. int scanf(const char * restrict, ...);
  4. int printf(const char *restrict, ...);
  5. void foo(char **sp, float *fp, int *ip) {
  6. scanf("%as", sp); /* expected-warning{{'a' length modifier is not supported by ISO C}} */
  7. scanf("%a[abc]", sp); /* expected-warning{{'a' length modifier is not supported by ISO C}} */
  8. /* TODO: Warn that the 'a' conversion specifier is a C99 feature. */
  9. scanf("%a", fp);
  10. scanf("%afoobar", fp);
  11. printf("%a", 1.0);
  12. printf("%as", 1.0);
  13. printf("%aS", 1.0);
  14. printf("%a[", 1.0);
  15. printf("%afoo", 1.0);
  16. scanf("%da", ip);
  17. /* Test argument type check for the 'a' length modifier. */
  18. scanf("%as", fp); /* expected-warning{{format specifies type 'char **' but the argument has type 'float *'}}
  19. expected-warning{{'a' length modifier is not supported by ISO C}} */
  20. scanf("%aS", fp); /* expected-warning{{format specifies type 'wchar_t **' (aka 'int **') but the argument has type 'float *'}}
  21. expected-warning{{'a' length modifier is not supported by ISO C}}
  22. expected-warning{{'S' conversion specifier is not supported by ISO C}} */
  23. scanf("%a[abc]", fp); /* expected-warning{{format specifies type 'char **' but the argument has type 'float *'}}
  24. expected-warning{{'a' length modifier is not supported by ISO C}} */
  25. }