fixit.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // RUN: %clang_cc1 -pedantic -Wunused-label -verify -x c %s
  2. // RUN: cp %s %t
  3. // RUN: not %clang_cc1 -pedantic -Wunused-label -fixit -x c %t
  4. // RUN: grep -v CHECK %t > %t2
  5. // RUN: %clang_cc1 -pedantic -Wunused-label -Werror -x c %t
  6. // RUN: FileCheck -input-file=%t2 %t
  7. /* This is a test of the various code modification hints that are
  8. provided as part of warning or extension diagnostics. All of the
  9. warnings will be fixed by -fixit, and the resulting file should
  10. compile cleanly with -Werror -pedantic. */
  11. // FIXME: FIX-IT should add #include <string.h>?
  12. int strcmp(const char *s1, const char *s2);
  13. void f0(void) { }; // expected-warning {{';'}}
  14. struct s {
  15. int x, y;; // expected-warning {{extra ';'}}
  16. };
  17. // CHECK: _Complex double cd;
  18. _Complex cd; // expected-warning {{assuming '_Complex double'}}
  19. // CHECK: struct s s0 = { .y = 5 };
  20. struct s s0 = { y: 5 }; // expected-warning {{GNU old-style}}
  21. // CHECK: int array0[5] = { [3] = 3 };
  22. int array0[5] = { [3] 3 }; // expected-warning {{GNU 'missing ='}}
  23. // CHECK: int x
  24. // CHECK: int y
  25. void f1(x, y) // expected-warning 2{{defaulting to type 'int'}}
  26. {
  27. }
  28. int i0 = { 17 };
  29. #define ONE 1
  30. #define TWO 2
  31. int test_cond(int y, int fooBar) { // expected-note {{here}}
  32. // CHECK: int x = y ? 1 : 4+fooBar;
  33. int x = y ? 1 4+foobar; // expected-error {{expected ':'}} expected-error {{undeclared identifier}} expected-note {{to match}}
  34. // CHECK: x = y ? ONE : TWO;
  35. x = y ? ONE TWO; // expected-error {{':'}} expected-note {{to match}}
  36. return x;
  37. }
  38. // CHECK: const typedef int int_t;
  39. const typedef typedef int int_t; // expected-warning {{duplicate 'typedef'}}
  40. // <rdar://problem/7159693>
  41. enum Color {
  42. Red // expected-error{{missing ',' between enumerators}}
  43. Green = 17 // expected-error{{missing ',' between enumerators}}
  44. Blue,
  45. };
  46. // rdar://9295072
  47. struct test_struct {
  48. // CHECK: struct test_struct *struct_ptr;
  49. test_struct *struct_ptr; // expected-error {{must use 'struct' tag to refer to type 'test_struct'}}
  50. };
  51. void removeUnusedLabels(char c) {
  52. L0 /*removed comment*/: c++; // expected-warning {{unused label}}
  53. removeUnusedLabels(c);
  54. L1: // expected-warning {{unused label}}
  55. c++;
  56. /*preserved comment*/ L2 : c++; // expected-warning {{unused label}}
  57. LL // expected-warning {{unused label}}
  58. : c++;
  59. c = c + 3; L4: return; // expected-warning {{unused label}}
  60. }
  61. int oopsAComma = 0, // expected-error {{';'}}
  62. void oopsMoreCommas() {
  63. static int a[] = { 0, 1, 2 }, // expected-error {{';'}}
  64. static int b[] = { 3, 4, 5 }, // expected-error {{';'}}
  65. &a == &b ? oopsMoreCommas() : removeUnusedLabels(a[0]);
  66. }
  67. int commaAtEndOfStatement() {
  68. int a = 1;
  69. a = 5, // expected-error {{';'}}
  70. int m = 5, // expected-error {{';'}}
  71. return 0, // expected-error {{';'}}
  72. }
  73. int noSemiAfterLabel(int n) {
  74. switch (n) {
  75. default:
  76. return n % 4;
  77. case 0:
  78. case 1:
  79. case 2:
  80. // CHECK: /*FOO*/ case 3: ;
  81. /*FOO*/ case 3: // expected-error {{expected statement}}
  82. }
  83. switch (n) {
  84. case 1:
  85. case 2:
  86. return 0;
  87. // CHECK: /*BAR*/ default: ;
  88. /*BAR*/ default: // expected-error {{expected statement}}
  89. }
  90. return 1;
  91. }
  92. struct noSemiAfterStruct // expected-error {{expected ';' after struct}}
  93. struct noSemiAfterStruct {
  94. int n // expected-warning {{';'}}
  95. } // expected-error {{expected ';' after struct}}
  96. enum noSemiAfterEnum {
  97. e1
  98. } // expected-error {{expected ';' after enum}}
  99. int PR17175 __attribute__((visibility(hidden))); // expected-error {{'visibility' attribute requires a string}}