format-strings-no-fixit.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // RUN: cp %s %t
  2. // RUN: %clang_cc1 -fsyntax-only -fixit %t
  3. // RUN: %clang_cc1 -E -o - %t | FileCheck %s
  4. /* This is a test of the various code modification hints that are
  5. provided as part of warning or extension diagnostics. Only
  6. warnings for format strings within the function call will be
  7. fixed by -fixit. Other format strings will be left alone. */
  8. int printf(char const *, ...);
  9. int scanf(char const *, ...);
  10. void pr9751() {
  11. const char kFormat1[] = "%s";
  12. printf(kFormat1, 5);
  13. printf("%s", 5);
  14. const char kFormat2[] = "%.3p";
  15. void *p;
  16. printf(kFormat2, p);
  17. printf("%.3p", p);
  18. const char kFormat3[] = "%0s";
  19. printf(kFormat3, "a");
  20. printf("%0s", "a");
  21. const char kFormat4[] = "%hhs";
  22. printf(kFormat4, "a");
  23. printf("%hhs", "a");
  24. const char kFormat5[] = "%-0d";
  25. printf(kFormat5, 5);
  26. printf("%-0d", 5);
  27. const char kFormat6[] = "%00d";
  28. int *i;
  29. scanf(kFormat6, i);
  30. scanf("%00d", i);
  31. }
  32. // CHECK: const char kFormat1[] = "%s";
  33. // CHECK: printf(kFormat1, 5);
  34. // CHECK: printf("%d", 5);
  35. // CHECK: const char kFormat2[] = "%.3p";
  36. // CHECK: void *p;
  37. // CHECK: printf(kFormat2, p);
  38. // CHECK: printf("%p", p);
  39. // CHECK: const char kFormat3[] = "%0s";
  40. // CHECK: printf(kFormat3, "a");
  41. // CHECK: printf("%s", "a");
  42. // CHECK: const char kFormat4[] = "%hhs";
  43. // CHECK: printf(kFormat4, "a");
  44. // CHECK: printf("%s", "a");
  45. // CHECK: const char kFormat5[] = "%-0d";
  46. // CHECK: printf(kFormat5, 5);
  47. // CHECK: printf("%-d", 5);
  48. // CHECK: const char kFormat6[] = "%00d";
  49. // CHECK: int *i;
  50. // CHECK: scanf(kFormat6, i);
  51. // CHECK: scanf("%d", i);