1 // RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s -triple x86_64-pc-win32
2 
3 // Multiple inheritance is involved (code segmments all disagree between the bases and derived class)
4 struct __declspec(code_seg("my_base")) Base1 {};
5 struct Base2 {};
6 
7 struct D1 : Base1, Base2 {};
8 // expected-error@-1 {{derived class must specify the same code segment as its base classes}}
9 // expected-note@4 {{base class 'Base1' specified here}}
10 
11 struct __declspec(code_seg("my_derived")) D2 : Base2, Base1 {};
12 // expected-error@-1 {{derived class must specify the same code segment as its base classes}}
13 // expected-error@-2 {{derived class must specify the same code segment as its base classes}}
14 // expected-note@5 {{base class 'Base2' specified here}}
15 // expected-note@4 {{base class 'Base1' specified here}}
16 
17 // Multiple inheritance (code segments partially agree between the bases and the derived class)
18 struct __declspec(code_seg("base_class")) BaseClass1 {};
19 struct __declspec(code_seg("base_class")) BaseClass2 {};
20 
21 struct Derived1 : BaseClass1, BaseClass2 {};
22 // expected-error@-1 {{derived class must specify the same code segment as its base classes}}
23 // expected-error@-2 {{derived class must specify the same code segment as its base classes}}
24 // expected-note@18 {{base class 'BaseClass1' specified here}}
25 // expected-note@19 {{base class 'BaseClass2' specified here}}
26 
27 struct __declspec(code_seg("derived_class")) Derived2 : BaseClass2, BaseClass1 {};
28 // expected-error@-1 {{derived class must specify the same code segment as its base classes}}
29 // expected-error@-2 {{derived class must specify the same code segment as its base classes}}
30 // expected-note@19 {{base class 'BaseClass2' specified here}}
31 // expected-note@18 {{base class 'BaseClass1' specified here}}
32 
33 struct __declspec(code_seg("base_class")) Derived3 : BaseClass2, BaseClass1 {}; //OK
34 struct __declspec(code_seg("base_class")) Derived4 : BaseClass1, BaseClass2 {}; //OK
35 
36 // Multiple inheritance is involved (code segmments all agree between the bases and derived class)
37 struct __declspec(code_seg("foo_base")) B1 {};
38 struct __declspec(code_seg("foo_base")) B2 {};
39 struct __declspec(code_seg("foo_base")) Derived : B1, B2 {};
40 
41 // virtual Inheritance is involved (code segmments all disagree between the bases and derived class)
42 struct __declspec(code_seg("my_one")) Base {
barABase43   virtual int barA() { return 1; } ;
44 };
45 
46 struct __declspec(code_seg("my_two")) Derived5 : virtual Base {
barBDerived547   virtual int barB() { return 2; };
48 };
49 // expected-error@-3 {{derived class must specify the same code segment as its base classes}}
50 // expected-note@42 {{base class 'Base' specified here}}
51 
52 struct __declspec(code_seg("my_three")) Derived6 : virtual Base {
barCDerived653   virtual int barC() { return 3; };
54 };
55 // expected-error@-3 {{derived class must specify the same code segment as its base classes}}
56 // expected-note@42 {{base class 'Base' specified here}}
57 
58 struct __declspec(code_seg("my_four")) Derived7 : Derived5, Derived6 {};
59 // expected-error@-1 {{derived class must specify the same code segment as its base classes}}
60 // expected-error@-2 {{derived class must specify the same code segment as its base classes}}
61 // expected-note@46 {{base class 'Derived5' specified here}}
62 // expected-note@52 {{base class 'Derived6' specified here}}
63 
64 // virtual Inheritance is involved (code segmments partially agree between the bases and derived class)
65 struct __declspec(code_seg("my_class")) BaseClass {
barABaseClass66   virtual int barA() { return 1; } ;
67 };
68 
69 struct __declspec(code_seg("my_class")) DerivedClass1 : virtual BaseClass { //OK
barBDerivedClass170   virtual int barB() { return 2; };
71 };
72 
73 struct __declspec(code_seg("my_class")) DerivedClass2 : virtual BaseClass { //OK
barCDerivedClass274   virtual int barC() { return 3; };
75 };
76 
77 struct __declspec(code_seg("my_derived_one")) DerivedClass3 : DerivedClass1, DerivedClass2 {};
78 // expected-error@-1 {{derived class must specify the same code segment as its base classes}}
79 // expected-error@-2 {{derived class must specify the same code segment as its base classes}}
80 // expected-note@69 {{base class 'DerivedClass1' specified here}}
81 // expected-note@73 {{base class 'DerivedClass2' specified here}}
82 
83 // virtual Inheritance is involved (code segmments all agree between the bases and derived class)
84 struct __declspec(code_seg("foo_one")) Class {
foo1Class85   virtual int foo1() { return 10; } ;
86 };
87 
88 struct __declspec(code_seg("foo_one")) Derived_One: virtual Class { //OK
foo2Derived_One89   virtual int foo2() { return 20; };
90 };
91 
92 struct __declspec(code_seg("foo_one")) Derived_Two : virtual Class { //OK
foo3Derived_Two93   virtual int foo3() { return 30; };
94 };
95 
96 struct __declspec(code_seg("foo_one")) Derived_Three : Derived_One, Derived_Two {}; //OK
97 
98