xref: /llvm-project/clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp (revision 5c24c316496e221e1841418f0f39ccb7200c83c6)
10faee97aSAmy Huang // RUN: %clang_cc1 -std=c++2a %s -verify=unsupported -triple x86_64-linux-gnu
20faee97aSAmy Huang // RUN: %clang_cc1 -std=c++2a %s -verify -triple x86_64-windows -fms-compatibility
30faee97aSAmy Huang 
40faee97aSAmy Huang [[msvc::no_unique_address]] int a; // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
50faee97aSAmy Huang [[msvc::no_unique_address]] void f(); // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
60faee97aSAmy Huang struct [[msvc::no_unique_address]] S { // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
70faee97aSAmy Huang   [[msvc::no_unique_address]] int a; // unsupported-warning {{unknown}}
80faee97aSAmy Huang   [[msvc::no_unique_address]] void f(); // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
90faee97aSAmy Huang   [[msvc::no_unique_address]] static int sa;// expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
100faee97aSAmy Huang   [[msvc::no_unique_address]] static void sf(); // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
110faee97aSAmy Huang   [[msvc::no_unique_address]] int b : 3; // expected-error {{only applies to non-bit-field non-static data members}} unsupported-warning {{unknown}}
120faee97aSAmy Huang 
130faee97aSAmy Huang   [[msvc::no_unique_address, msvc::no_unique_address]] int duplicated; // ok
140faee97aSAmy Huang   // unsupported-warning@-1 2{{unknown}}
150faee97aSAmy Huang   [[msvc::no_unique_address]] [[msvc::no_unique_address]] int duplicated2; // unsupported-warning 2{{unknown}}
160faee97aSAmy Huang   [[msvc::no_unique_address()]] int arglist; // expected-error {{cannot have an argument list}} unsupported-warning {{unknown}}
170faee97aSAmy Huang 
180faee97aSAmy Huang   int [[msvc::no_unique_address]] c; // expected-error {{cannot be applied to types}} unsupported-error {{cannot be applied to types}}
190faee97aSAmy Huang };
20*5c24c316SVlad Serebrennikov 
21*5c24c316SVlad Serebrennikov struct CStructNoUniqueAddress {
22*5c24c316SVlad Serebrennikov   int one;
23*5c24c316SVlad Serebrennikov   [[no_unique_address]] int two;
24*5c24c316SVlad Serebrennikov   // expected-warning@-1 {{unknown attribute 'no_unique_address' ignored}}
25*5c24c316SVlad Serebrennikov };
26*5c24c316SVlad Serebrennikov 
27*5c24c316SVlad Serebrennikov struct CStructMSVCNoUniqueAddress {
28*5c24c316SVlad Serebrennikov   int one;
29*5c24c316SVlad Serebrennikov   [[msvc::no_unique_address]] int two;
30*5c24c316SVlad Serebrennikov   // unsupported-warning@-1 {{unknown attribute 'no_unique_address' ignored}}
31*5c24c316SVlad Serebrennikov };
32*5c24c316SVlad Serebrennikov 
33*5c24c316SVlad Serebrennikov struct CStructMSVCNoUniqueAddress2 {
34*5c24c316SVlad Serebrennikov   int one;
35*5c24c316SVlad Serebrennikov   [[msvc::no_unique_address]] int two;
36*5c24c316SVlad Serebrennikov   // unsupported-warning@-1 {{unknown attribute 'no_unique_address' ignored}}
37*5c24c316SVlad Serebrennikov };
38*5c24c316SVlad Serebrennikov 
39*5c24c316SVlad Serebrennikov static_assert(__has_cpp_attribute(no_unique_address) == 0);
40*5c24c316SVlad Serebrennikov // unsupported-error@-1 {{static assertion failed due to requirement '201803L == 0'}}
41*5c24c316SVlad Serebrennikov static_assert(!__is_layout_compatible(CStructNoUniqueAddress, CStructMSVCNoUniqueAddress), "");
42*5c24c316SVlad Serebrennikov static_assert(__is_layout_compatible(CStructMSVCNoUniqueAddress, CStructMSVCNoUniqueAddress), "");
43*5c24c316SVlad Serebrennikov static_assert(!__is_layout_compatible(CStructMSVCNoUniqueAddress, CStructMSVCNoUniqueAddress2), "");
44*5c24c316SVlad Serebrennikov // unsupported-error@-1 {{static assertion failed due to requirement '!__is_layout_compatible(CStructMSVCNoUniqueAddress, CStructMSVCNoUniqueAddress2)':}}
45