MicrosoftExtensions.cpp revision eedd4670b2eb7e4d67d11b2f26ed1ad304b70596
1018591f524ca4f3a1e657d0d0a66eadf9dbd55f6John McCall// RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions -fexceptions -fcxx-exceptions
25c0ca52e40e0b9e3c2da7abba47b18e468c84060Douglas Gregor
35c0ca52e40e0b9e3c2da7abba47b18e468c84060Douglas Gregor
45c0ca52e40e0b9e3c2da7abba47b18e468c84060Douglas Gregor// ::type_info is predeclared with forward class declartion
55c0ca52e40e0b9e3c2da7abba47b18e468c84060Douglas Gregorvoid f(const type_info &a);
65c0ca52e40e0b9e3c2da7abba47b18e468c84060Douglas Gregor
75b6f769a6abda4da44186cc8e6a2d6ed37dc9344Douglas Gregor
8eedd4670b2eb7e4d67d11b2f26ed1ad304b70596Francois Pichet// Microsoft doesn't validate exception specification.
9eedd4670b2eb7e4d67d11b2f26ed1ad304b70596Francois Pichetvoid foo(); // expected-note {{previous declaration}}
10eedd4670b2eb7e4d67d11b2f26ed1ad304b70596Francois Pichetvoid foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}}
115b6f769a6abda4da44186cc8e6a2d6ed37dc9344Douglas Gregor
12eedd4670b2eb7e4d67d11b2f26ed1ad304b70596Francois Pichetvoid r6() throw(...); // expected-note {{previous declaration}}
13eedd4670b2eb7e4d67d11b2f26ed1ad304b70596Francois Pichetvoid r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}}
145b6f769a6abda4da44186cc8e6a2d6ed37dc9344Douglas Gregor
155b6f769a6abda4da44186cc8e6a2d6ed37dc9344Douglas Gregorstruct Base {
165b6f769a6abda4da44186cc8e6a2d6ed37dc9344Douglas Gregor  virtual void f2();
175b6f769a6abda4da44186cc8e6a2d6ed37dc9344Douglas Gregor  virtual void f3() throw(...);
185b6f769a6abda4da44186cc8e6a2d6ed37dc9344Douglas Gregor};
195b6f769a6abda4da44186cc8e6a2d6ed37dc9344Douglas Gregor
205b6f769a6abda4da44186cc8e6a2d6ed37dc9344Douglas Gregorstruct Derived : Base {
215b6f769a6abda4da44186cc8e6a2d6ed37dc9344Douglas Gregor  virtual void f2() throw(...);
225b6f769a6abda4da44186cc8e6a2d6ed37dc9344Douglas Gregor  virtual void f3();
235b6f769a6abda4da44186cc8e6a2d6ed37dc9344Douglas Gregor};
24afac01d7e76f28d5e5a5c377369cc400919387eeDouglas Gregor
25538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet
26538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet// MSVC allows type definition in anonymous union and struct
27538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichetstruct A
28538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet{
29538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet  union
30538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet  {
31538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    int a;
32538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    struct B  // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
33538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    {
34538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet      int c;
35538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    } d;
36538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet
37538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    union C   // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
38538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    {
39538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet      int e;
40538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet      int ee;
41538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    } f;
42538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet
43538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    typedef int D;  // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
44538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    struct F;  // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
45538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet  };
46538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet
47538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet  struct
48538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet  {
49538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    int a2;
50538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet
51538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    struct B2  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
52538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    {
53538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet      int c2;
54538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    } d2;
55538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet
56538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet	union C2  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
57538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    {
58538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet      int e2;
59538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet      int ee2;
60538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    } f2;
61538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet
62538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    typedef int D2;  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
63538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet    struct F2;  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
64538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet  };
65538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet};
66538e0d0292cab16198a4fce5c388ff06adc74d0cFrancois Pichet
67afac01d7e76f28d5e5a5c377369cc400919387eeDouglas Gregor// __stdcall handling
68afac01d7e76f28d5e5a5c377369cc400919387eeDouglas Gregorstruct M {
69afac01d7e76f28d5e5a5c377369cc400919387eeDouglas Gregor    int __stdcall addP();
70afac01d7e76f28d5e5a5c377369cc400919387eeDouglas Gregor    float __stdcall subtractP();
71afac01d7e76f28d5e5a5c377369cc400919387eeDouglas Gregor};
72afac01d7e76f28d5e5a5c377369cc400919387eeDouglas Gregor
73afac01d7e76f28d5e5a5c377369cc400919387eeDouglas Gregortemplate<typename T> void h1(T (__stdcall M::* const )()) { }
74afac01d7e76f28d5e5a5c377369cc400919387eeDouglas Gregor
75afac01d7e76f28d5e5a5c377369cc400919387eeDouglas Gregorvoid m1() {
76afac01d7e76f28d5e5a5c377369cc400919387eeDouglas Gregor  h1<int>(&M::addP);
77afac01d7e76f28d5e5a5c377369cc400919387eeDouglas Gregor  h1(&M::subtractP);
78afac01d7e76f28d5e5a5c377369cc400919387eeDouglas Gregor}
798dc3abcc36df883324461daad0c05364158f3cf0Francois Pichet
808dc3abcc36df883324461daad0c05364158f3cf0Francois Pichet//MSVC allows forward enum declaration
818dc3abcc36df883324461daad0c05364158f3cf0Francois Pichetenum ENUM; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
82842e7a22c6a0fbf0ccdb4bb9308d92ca9e9621f6Francois PichetENUM *var = 0;
83842e7a22c6a0fbf0ccdb4bb9308d92ca9e9621f6Francois PichetENUM var2 = (ENUM)3;
84842e7a22c6a0fbf0ccdb4bb9308d92ca9e9621f6Francois Pichetenum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}}
85842e7a22c6a0fbf0ccdb4bb9308d92ca9e9621f6Francois Pichet
86842e7a22c6a0fbf0ccdb4bb9308d92ca9e9621f6Francois Pichet
87842e7a22c6a0fbf0ccdb4bb9308d92ca9e9621f6Francois Pichetenum ENUM2 {
88842e7a22c6a0fbf0ccdb4bb9308d92ca9e9621f6Francois Pichet	ENUM2_a = (enum ENUM2) 4,
89842e7a22c6a0fbf0ccdb4bb9308d92ca9e9621f6Francois Pichet	ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
90842e7a22c6a0fbf0ccdb4bb9308d92ca9e9621f6Francois Pichet	ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
91842e7a22c6a0fbf0ccdb4bb9308d92ca9e9621f6Francois Pichet};
925be38be82a6631786624625d010d695d529802a8Francois Pichet
935be38be82a6631786624625d010d695d529802a8Francois Pichet
945be38be82a6631786624625d010d695d529802a8Francois Pichetvoid f(long long);
955be38be82a6631786624625d010d695d529802a8Francois Pichetvoid f(int);
965be38be82a6631786624625d010d695d529802a8Francois Pichet
975be38be82a6631786624625d010d695d529802a8Francois Pichetint main()
985be38be82a6631786624625d010d695d529802a8Francois Pichet{
995be38be82a6631786624625d010d695d529802a8Francois Pichet  // This is an ambiguous call in standard C++.
1005be38be82a6631786624625d010d695d529802a8Francois Pichet  // This calls f(long long) in Microsoft mode because LL is always signed.
1015be38be82a6631786624625d010d695d529802a8Francois Pichet  f(0xffffffffffffffffLL);
1025be38be82a6631786624625d010d695d529802a8Francois Pichet  f(0xffffffffffffffffi64);
1035be38be82a6631786624625d010d695d529802a8Francois Pichet}
10486f208c1a112c3e8984e63daec15ccf0a1a84329Douglas Gregor
10586f208c1a112c3e8984e63daec15ccf0a1a84329Douglas Gregor// Enumeration types with a fixed underlying type.
10686f208c1a112c3e8984e63daec15ccf0a1a84329Douglas Gregorconst int seventeen = 17;
10786f208c1a112c3e8984e63daec15ccf0a1a84329Douglas Gregortypedef int Int;
10886f208c1a112c3e8984e63daec15ccf0a1a84329Douglas Gregor
10986f208c1a112c3e8984e63daec15ccf0a1a84329Douglas Gregorstruct X0 {
11086f208c1a112c3e8984e63daec15ccf0a1a84329Douglas Gregor  enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
11186f208c1a112c3e8984e63daec15ccf0a1a84329Douglas Gregor  enum E1 : seventeen;
11286f208c1a112c3e8984e63daec15ccf0a1a84329Douglas Gregor};
11386f208c1a112c3e8984e63daec15ccf0a1a84329Douglas Gregor
1141756ce44b0e03d6a6fd2d42add6e3227d4d04d34Douglas Gregorenum : long long {  // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
11586f208c1a112c3e8984e63daec15ccf0a1a84329Douglas Gregor  SomeValue = 0x100000000
11686f208c1a112c3e8984e63daec15ccf0a1a84329Douglas Gregor};
117