1 // RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s -triple x86_64-pc-win32 2 3 struct __declspec(code_seg("my_one")) FooOne { 4 int barC(); 5 }; 6 7 struct FooTwo { 8 int __declspec(code_seg("my_three")) barD(); 9 int barE(); 10 }; 11 int __declspec(code_seg("my_four")) FooOne::barC() { return 10; } 12 // expected-warning@-1 {{codeseg does not match previous declaration}} 13 // expected-note@3{{previous attribute is here}} 14 int __declspec(code_seg("my_five")) FooTwo::barD() { return 20; } 15 // expected-warning@-1 {{codeseg does not match previous declaration}} 16 // expected-note@8 {{previous attribute is here}} 17 int __declspec(code_seg("my_six")) FooTwo::barE() { return 30; } 18 // expected-warning@-1 {{codeseg does not match previous declaration}} 19 // expected-note@9 {{previous declaration is here}} 20 21 // Microsoft docs say: 22 // If a base-class has a code_seg attribute, derived classes must have the 23 // same attribute. 24 struct __declspec(code_seg("my_base")) Base1 {}; 25 struct Base2 {}; 26 27 struct D1 : Base1 {}; 28 //expected-error@-1 {{derived class must specify the same code segment as its base classes}} 29 // expected-note@24 {{base class 'Base1' specified here}} 30 struct __declspec(code_seg("my_derived")) D2 : Base1 {}; 31 // expected-error@-1 {{derived class must specify the same code segment as its base classes}} 32 // expected-note@24 {{base class 'Base1' specified here}} 33 struct __declspec(code_seg("my_derived")) D3 : Base2 {}; 34 // expected-error@-1 {{derived class must specify the same code segment as its base classes}} 35 // expected-note@25 {{base class 'Base2' specified here}} 36 37 template <typename T> struct __declspec(code_seg("my_base")) MB : T { }; 38 template <typename T> struct __declspec(code_seg("my_derived")) MD : T { }; 39 MB<Base1> mb1; // ok 40 MB<Base2> mb2; 41 // expected-error@37 {{derived class must specify the same code segment as its base classes}} 42 // expected-note@-2 {{in instantiation of template class}} 43 // expected-note@25 {{base class 'Base2' specified here}} 44 MD<Base1> md1; 45 // expected-error@38 {{derived class must specify the same code segment as its base classes}} 46 // expected-note@-2 {{in instantiation of template class}} 47 // expected-note@24 {{base class 'Base1' specified here}} 48 MD<Base2> md2; 49 // expected-error@38 {{derived class must specify the same code segment as its base classes}} 50 // expected-note@-2 {{in instantiation of template class}} 51 // expected-note@25 {{base class 'Base2' specified here}} 52 53 // Virtual overrides must have the same code_seg. 54 struct __declspec(code_seg("my_one")) Base3 { 55 virtual int barA() { return 1; } 56 virtual int __declspec(code_seg("my_two")) barB() { return 2; } 57 }; 58 struct __declspec(code_seg("my_one")) Derived3 : Base3 { 59 int barA() { return 4; } // ok 60 int barB() { return 6; } 61 // expected-error@-1 {{overriding virtual function must specify the same code segment as its overridden function}} 62 // expected-note@56 {{previous declaration is here}} 63 }; 64 65 struct Base4 { 66 virtual int __declspec(code_seg("my_one")) barA() {return 1;} 67 virtual int barB() { return 2;} 68 }; 69 struct Derived4 : Base4 { 70 virtual int barA() {return 1;} 71 // expected-error@-1 {{overriding virtual function must specify the same code segment as its overridden function}} 72 // expected-note@66 {{previous declaration is here}} 73 virtual int __declspec(code_seg("my_two")) barB() {return 1;} 74 // expected-error@-1 {{overriding virtual function must specify the same code segment as its overridden function}} 75 // expected-note@67 {{previous declaration is here}} 76 }; 77 78 // MS gives an error when different code segments are used but a warning when a duplicate is used 79 80 // Function 81 int __declspec(code_seg("foo")) __declspec(code_seg("foo")) bar1() { return 1; } 82 // expected-warning@-1 {{duplicate code segment specifiers}} 83 int __declspec(code_seg("foo")) __declspec(code_seg("bar")) bar2() { return 1; } 84 // expected-error@-1 {{conflicting code segment specifiers}} 85 86 // Class 87 struct __declspec(code_seg("foo")) __declspec(code_seg("foo")) Foo { 88 // expected-warning@-1 {{duplicate code segment specifiers}} 89 int bar3() {return 0;} 90 }; 91 struct __declspec(code_seg("foo")) __declspec(code_seg("bar")) FooSix { 92 // expected-error@-1 {{conflicting code segment specifiers}} 93 int bar3() {return 0;} 94 }; 95 96 //Class Members 97 struct FooThree { 98 int __declspec(code_seg("foo")) __declspec(code_seg("foo")) bar1() { return 1; } 99 // expected-warning@-1 {{duplicate code segment specifiers}} 100 int __declspec(code_seg("foo")) __declspec(code_seg("bar")) bar2() { return 1; } 101 // expected-error@-1 {{conflicting code segment specifiers}} 102 int bar8(); 103 int bar9() { return 9; } 104 }; 105 106