xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/ms_struct.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -Wno-error=incompatible-ms-struct -verify -triple i686-apple-darwin9 -std=c++11 %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -Wno-error=incompatible-ms-struct -verify -triple armv7-apple-darwin9 -std=c++11 %s
3*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -DTEST_FOR_ERROR -verify -triple armv7-apple-darwin9 -std=c++11 %s
4f4a2713aSLionel Sambuc 
5f4a2713aSLionel Sambuc #pragma ms_struct on
6f4a2713aSLionel Sambuc 
7f4a2713aSLionel Sambuc struct A {
8f4a2713aSLionel Sambuc   unsigned long a:4;
9f4a2713aSLionel Sambuc   unsigned char b;
10f4a2713aSLionel Sambuc };
11f4a2713aSLionel Sambuc 
12f4a2713aSLionel Sambuc struct B : public A {
13*0a6a1f1dSLionel Sambuc #ifdef TEST_FOR_ERROR
14*0a6a1f1dSLionel Sambuc   // expected-error@-2 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
15*0a6a1f1dSLionel Sambuc #else
16*0a6a1f1dSLionel Sambuc   // expected-warning@-4 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
17*0a6a1f1dSLionel Sambuc #endif
18f4a2713aSLionel Sambuc   unsigned long c:16;
19f4a2713aSLionel Sambuc 	int d;
20f4a2713aSLionel Sambuc   B();
21f4a2713aSLionel Sambuc };
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc static_assert(__builtin_offsetof(B, d) == 12,
24f4a2713aSLionel Sambuc   "We can't allocate the bitfield into the padding under ms_struct");
25*0a6a1f1dSLionel Sambuc 
26*0a6a1f1dSLionel Sambuc // rdar://16178895
27*0a6a1f1dSLionel Sambuc struct C {
28*0a6a1f1dSLionel Sambuc #ifdef TEST_FOR_ERROR
29*0a6a1f1dSLionel Sambuc   // expected-error@-2 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
30*0a6a1f1dSLionel Sambuc #else
31*0a6a1f1dSLionel Sambuc   // expected-warning@-4 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
32*0a6a1f1dSLionel Sambuc #endif
33*0a6a1f1dSLionel Sambuc   virtual void foo();
34*0a6a1f1dSLionel Sambuc   long long n;
35*0a6a1f1dSLionel Sambuc };
36*0a6a1f1dSLionel Sambuc 
37*0a6a1f1dSLionel Sambuc static_assert(__builtin_offsetof(C, n) == 8,
38*0a6a1f1dSLionel Sambuc               "long long field in ms_struct should be 8-byte aligned");
39