MicrosoftExtensions.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions
  2. struct A
  3. {
  4. int a[]; /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */
  5. };
  6. struct C {
  7. int l;
  8. union {
  9. int c1[]; /* expected-warning {{flexible array member 'c1' in a union is a Microsoft extension}} */
  10. char c2[]; /* expected-warning {{flexible array member 'c2' in a union is a Microsoft extension}} */
  11. };
  12. };
  13. struct D {
  14. int l;
  15. int D[];
  16. };
  17. struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {}; /* expected-error {{'uuid' attribute is not supported in C}} */
  18. typedef struct notnested {
  19. long bad1;
  20. long bad2;
  21. } NOTNESTED;
  22. typedef struct nested1 {
  23. long a;
  24. struct notnested var1;
  25. NOTNESTED var2;
  26. } NESTED1;
  27. struct nested2 {
  28. long b;
  29. NESTED1; // expected-warning {{anonymous structs are a Microsoft extension}}
  30. };
  31. struct nested2 PR20573 = { .a = 3 };
  32. struct nested3 {
  33. long d;
  34. struct nested4 { // expected-warning {{anonymous structs are a Microsoft extension}}
  35. long e;
  36. };
  37. union nested5 { // expected-warning {{anonymous unions are a Microsoft extension}}
  38. long f;
  39. };
  40. };
  41. typedef union nested6 {
  42. long f;
  43. } NESTED6;
  44. struct test {
  45. int c;
  46. struct nested2; // expected-warning {{anonymous structs are a Microsoft extension}}
  47. NESTED6; // expected-warning {{anonymous unions are a Microsoft extension}}
  48. };
  49. void foo()
  50. {
  51. struct test var;
  52. var.a;
  53. var.b;
  54. var.c;
  55. var.bad1; // expected-error {{no member named 'bad1' in 'struct test'}}
  56. var.bad2; // expected-error {{no member named 'bad2' in 'struct test'}}
  57. }
  58. // Enumeration types with a fixed underlying type.
  59. const int seventeen = 17;
  60. typedef int Int;
  61. struct X0 {
  62. enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
  63. enum E1 : seventeen;
  64. };
  65. enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
  66. SomeValue = 0x100000000
  67. };
  68. void pointer_to_integral_type_conv(char* ptr) {
  69. char ch = (char)ptr;
  70. short sh = (short)ptr;
  71. ch = (char)ptr;
  72. sh = (short)ptr;
  73. // This is valid ISO C.
  74. _Bool b = (_Bool)ptr;
  75. }
  76. typedef struct {
  77. UNKNOWN u; // expected-error {{unknown type name 'UNKNOWN'}}
  78. } AA;
  79. typedef struct {
  80. AA; // expected-warning {{anonymous structs are a Microsoft extension}}
  81. } BB;
  82. struct anon_fault {
  83. struct undefined; // expected-warning {{anonymous structs are a Microsoft extension}}
  84. // expected-error@-1 {{field has incomplete type 'struct undefined'}}
  85. // expected-note@-2 {{forward declaration of 'struct undefined'}}
  86. };
  87. const int anon_falt_size = sizeof(struct anon_fault);
  88. __declspec(deprecated("This is deprecated")) enum DE1 { one, two } e1; // expected-note {{'e1' has been explicitly marked deprecated here}}
  89. struct __declspec(deprecated) DS1 { int i; float f; }; // expected-note {{'DS1' has been explicitly marked deprecated here}}
  90. #define MY_TEXT "This is also deprecated"
  91. __declspec(deprecated(MY_TEXT)) void Dfunc1( void ) {} // expected-note {{'Dfunc1' has been explicitly marked deprecated here}}
  92. struct __declspec(deprecated(123)) DS2 {}; // expected-error {{'deprecated' attribute requires a string}}
  93. void test( void ) {
  94. e1 = one; // expected-warning {{'e1' is deprecated: This is deprecated}}
  95. struct DS1 s = { 0 }; // expected-warning {{'DS1' is deprecated}}
  96. Dfunc1(); // expected-warning {{'Dfunc1' is deprecated: This is also deprecated}}
  97. enum DE1 no; // no warning because E1 is not deprecated
  98. }
  99. int __sptr wrong1; // expected-error {{'__sptr' attribute only applies to pointer arguments}}
  100. // The modifier must follow the asterisk
  101. int __sptr *wrong_psp; // expected-error {{'__sptr' attribute only applies to pointer arguments}}
  102. int * __sptr __uptr wrong2; // expected-error {{'__sptr' and '__uptr' attributes are not compatible}}
  103. int * __sptr __sptr wrong3; // expected-warning {{attribute '__sptr' is already applied}}
  104. // It is illegal to overload based on the type attribute.
  105. void ptr_func(int * __ptr32 i) {} // expected-note {{previous definition is here}}
  106. void ptr_func(int * __ptr64 i) {} // expected-error {{redefinition of 'ptr_func'}}
  107. // It is also illegal to overload based on the pointer type attribute.
  108. void ptr_func2(int * __sptr __ptr32 i) {} // expected-note {{previous definition is here}}
  109. void ptr_func2(int * __uptr __ptr32 i) {} // expected-error {{redefinition of 'ptr_func2'}}
  110. int * __sptr __ptr32 __sptr wrong4; // expected-warning {{attribute '__sptr' is already applied}}
  111. __ptr32 int *wrong5; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
  112. int *wrong6 __ptr32; // expected-error {{expected ';' after top level declarator}} expected-warning {{declaration does not declare anything}}
  113. int * __ptr32 __ptr64 wrong7; // expected-error {{'__ptr32' and '__ptr64' attributes are not compatible}}
  114. int * __ptr32 __ptr32 wrong8; // expected-warning {{attribute '__ptr32' is already applied}}
  115. int *(__ptr32 __sptr wrong9); // expected-error {{'__sptr' attribute only applies to pointer arguments}} // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
  116. typedef int *T;
  117. T __ptr32 wrong10; // expected-error {{'__ptr32' attribute only applies to pointer arguments}}
  118. typedef char *my_va_list;
  119. void __va_start(my_va_list *ap, ...); // expected-note {{passing argument to parameter 'ap' here}}
  120. void vmyprintf(const char *f, my_va_list ap);
  121. void myprintf(const char *f, ...) {
  122. my_va_list ap;
  123. if (1) {
  124. __va_start(&ap, f);
  125. vmyprintf(f, ap);
  126. ap = 0;
  127. } else {
  128. __va_start(ap, f); // expected-warning {{incompatible pointer types passing 'my_va_list'}}
  129. }
  130. }