gnu-flags.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wno-gnu
  2. // RUN: %clang_cc1 -fsyntax-only -verify %s -DALL -Wgnu
  3. // RUN: %clang_cc1 -fsyntax-only -verify %s -DALL -Wno-gnu \
  4. // RUN: -Wgnu-alignof-expression -Wgnu-case-range -Wgnu-complex-integer -Wgnu-conditional-omitted-operand \
  5. // RUN: -Wgnu-empty-initializer -Wgnu-label-as-value -Wgnu-statement-expression \
  6. // RUN: -Wgnu-compound-literal-initializer -Wgnu-flexible-array-initializer \
  7. // RUN: -Wgnu-redeclared-enum -Wgnu-folding-constant -Wgnu-empty-struct \
  8. // RUN: -Wgnu-union-cast -Wgnu-variable-sized-type-not-at-end
  9. // RUN: %clang_cc1 -fsyntax-only -verify %s -DNONE -Wgnu \
  10. // RUN: -Wno-gnu-alignof-expression -Wno-gnu-case-range -Wno-gnu-complex-integer -Wno-gnu-conditional-omitted-operand \
  11. // RUN: -Wno-gnu-empty-initializer -Wno-gnu-label-as-value -Wno-gnu-statement-expression \
  12. // RUN: -Wno-gnu-compound-literal-initializer -Wno-gnu-flexible-array-initializer \
  13. // RUN: -Wno-gnu-redeclared-enum -Wno-gnu-folding-constant -Wno-gnu-empty-struct \
  14. // RUN: -Wno-gnu-union-cast -Wno-gnu-variable-sized-type-not-at-end
  15. // Additional disabled tests:
  16. // %clang_cc1 -fsyntax-only -verify %s -DALIGNOF -Wno-gnu -Wgnu-alignof-expression
  17. // %clang_cc1 -fsyntax-only -verify %s -DCASERANGE -Wno-gnu -Wgnu-case-range
  18. // %clang_cc1 -fsyntax-only -verify %s -DCOMPLEXINT -Wno-gnu -Wgnu-complex-integer
  19. // %clang_cc1 -fsyntax-only -verify %s -DOMITTEDOPERAND -Wno-gnu -Wgnu-conditional-omitted-operand
  20. // %clang_cc1 -fsyntax-only -verify %s -DEMPTYINIT -Wno-gnu -Wgnu-empty-initializer
  21. // %clang_cc1 -fsyntax-only -verify %s -DLABELVALUE -Wno-gnu -Wgnu-label-as-value
  22. // %clang_cc1 -fsyntax-only -verify %s -DSTATEMENTEXP -Wno-gnu -Wgnu-statement-expression
  23. // %clang_cc1 -fsyntax-only -verify %s -DCOMPOUNDLITERALINITIALIZER -Wno-gnu -Wgnu-compound-literal-initializer
  24. // %clang_cc1 -fsyntax-only -verify %s -DFLEXIBLEARRAYINITIALIZER -Wno-gnu -Wgnu-flexible-array-initializer
  25. // %clang_cc1 -fsyntax-only -verify %s -DREDECLAREDENUM -Wno-gnu -Wgnu-redeclared-enum
  26. // %clang_cc1 -fsyntax-only -verify %s -DUNIONCAST -Wno-gnu -Wgnu-union-cast
  27. // %clang_cc1 -fsyntax-only -verify %s -DVARIABLESIZEDTYPENOTATEND -Wno-gnu -Wgnu-variable-sized-type-not-at-end
  28. // %clang_cc1 -fsyntax-only -verify %s -DFOLDINGCONSTANT -Wno-gnu -Wgnu-folding-constant
  29. // %clang_cc1 -fsyntax-only -verify %s -DEMPTYSTRUCT -Wno-gnu -Wgnu-empty-struct
  30. #if NONE
  31. // expected-no-diagnostics
  32. #endif
  33. #if ALL || ALIGNOF
  34. // expected-warning@+4 {{'_Alignof' applied to an expression is a GNU extension}}
  35. #endif
  36. char align;
  37. _Static_assert(_Alignof(align) > 0, "align's alignment is wrong");
  38. #if ALL || CASERANGE
  39. // expected-warning@+5 {{use of GNU case range extension}}
  40. #endif
  41. void caserange(int x) {
  42. switch (x) {
  43. case 42 ... 44: ;
  44. }
  45. }
  46. #if ALL || COMPLEXINT
  47. // expected-warning@+3 {{complex integer types are a GNU extension}}
  48. #endif
  49. _Complex short int complexint;
  50. #if ALL || OMITTEDOPERAND
  51. // expected-warning@+3 {{use of GNU ?: conditional expression extension, omitting middle operand}}
  52. #endif
  53. static const char* omittedoperand = (const char*)0 ?: "Null";
  54. #if ALL || EMPTYINIT
  55. // expected-warning@+3 {{use of GNU empty initializer extension}}
  56. #endif
  57. struct { int x; } emptyinit = {};
  58. #if ALL || LABELVALUE
  59. // expected-warning@+6 {{use of GNU address-of-label extension}}
  60. // expected-warning@+7 {{use of GNU indirect-goto extension}}
  61. #endif
  62. void labelvalue() {
  63. void *ptr;
  64. ptr = &&foo;
  65. foo:
  66. goto *ptr;
  67. }
  68. #if ALL || STATEMENTEXP
  69. // expected-warning@+5 {{use of GNU statement expression extension}}
  70. #endif
  71. void statementexp()
  72. {
  73. int a = ({ 1; });
  74. }
  75. #if ALL || COMPOUNDLITERALINITIALIZER
  76. // expected-warning@+4 {{initialization of an array of type 'int [5]' from a compound literal of type 'int [5]' is a GNU extension}}
  77. #endif
  78. typedef int int5[5];
  79. int cli[5] = (int[]){1, 2, 3, 4, 5};
  80. #if ALL || FLEXIBLEARRAYINITIALIZER
  81. // expected-note@+6 {{initialized flexible array member 'y' is here}}
  82. // expected-warning@+6 {{flexible array initialization is a GNU extension}}
  83. #endif
  84. struct fai {
  85. int x;
  86. int y[];
  87. } fai = { 1, { 2, 3, 4 } };
  88. #if ALL || FOLDINGCONSTANT
  89. // expected-warning@+5 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
  90. // expected-warning@+7 {{variable length array folded to constant array as an extension}}
  91. #endif
  92. enum {
  93. fic = (int)(0.75 * 1000 * 1000)
  94. };
  95. static const int size = 100;
  96. void foo(void) { int data[size]; }
  97. #if ALL || REDECLAREDENUM
  98. // expected-note@+4 {{previous definition is here}}
  99. // expected-warning@+8 {{redeclaration of already-defined enum 'RE' is a GNU extension}}
  100. #endif
  101. enum RE {
  102. Val1,
  103. Val2
  104. };
  105. enum RE;
  106. #if ALL || UNIONCAST
  107. // expected-warning@+4 {{cast to union type is a GNU extension}}
  108. #endif
  109. union uc { int i; unsigned : 3; };
  110. union uc w = (union uc)2;
  111. #if ALL || VARIABLESIZEDTYPENOTATEND
  112. // expected-warning@+8 {{field 'hdr' with variable sized type 'struct vst' not at the end of a struct or class is a GNU extension}}
  113. #endif
  114. struct vst {
  115. short tag_type;
  116. char tag_data[];
  117. };
  118. struct vstnae {
  119. struct vst hdr;
  120. char data;
  121. };
  122. #if ALL || EMPTYSTRUCT
  123. // expected-warning@+4 {{empty struct is a GNU extension}}
  124. // expected-warning@+4 {{struct without named members is a GNU extension}}
  125. #endif
  126. const struct {} es;
  127. struct {int:5;} swnm;