@@ -1622,7 +1622,7 @@ enum class EnumClassLayout {};
1622
1622
enum EnumForward : int ;
1623
1623
enum class EnumClassForward ;
1624
1624
1625
- struct CStructIncomplete ;
1625
+ struct CStructIncomplete ; // #CStructIncomplete
1626
1626
1627
1627
struct CStructNested {
1628
1628
int a;
@@ -1719,6 +1719,20 @@ struct StructWithAnonUnion3 {
1719
1719
} u;
1720
1720
};
1721
1721
1722
+ struct CStructWithArrayAtTheEnd {
1723
+ int a;
1724
+ int b[4 ];
1725
+ };
1726
+
1727
+ struct CStructWithFMA {
1728
+ int c;
1729
+ int d[];
1730
+ };
1731
+
1732
+ struct CStructWithFMA2 {
1733
+ int e;
1734
+ int f[];
1735
+ };
1722
1736
1723
1737
void is_layout_compatible (int n)
1724
1738
{
@@ -1800,15 +1814,28 @@ void is_layout_compatible(int n)
1800
1814
static_assert (__is_layout_compatible (EnumLayout, EnumClassLayout));
1801
1815
static_assert (__is_layout_compatible (EnumForward, EnumForward));
1802
1816
static_assert (__is_layout_compatible (EnumForward, EnumClassForward));
1803
- // Layout compatibility for enums might be relaxed in the future. See https://github.com/cplusplus/CWG/issues/39#issuecomment-1184791364
1817
+ static_assert (__is_layout_compatible (CStructIncomplete, CStructIncomplete));
1818
+ // expected-error@-1 {{incomplete type 'CStructIncomplete' where a complete type is required}}
1819
+ // expected-note@#CStructIncomplete {{forward declaration of 'CStructIncomplete'}}
1820
+ // expected-error@-3 {{incomplete type 'CStructIncomplete' where a complete type is required}}
1821
+ // expected-note@#CStructIncomplete {{forward declaration of 'CStructIncomplete'}}
1822
+ static_assert (!__is_layout_compatible (CStruct, CStructIncomplete));
1823
+ // expected-error@-1 {{incomplete type 'CStructIncomplete' where a complete type is required}}
1824
+ // expected-note@#CStructIncomplete {{forward declaration of 'CStructIncomplete'}}
1825
+ static_assert (__is_layout_compatible (CStructIncomplete[2 ], CStructIncomplete[2 ]));
1826
+ // expected-error@-1 {{incomplete type 'CStructIncomplete[2]' where a complete type is required}}
1827
+ // expected-note@#CStructIncomplete {{forward declaration of 'CStructIncomplete'}}
1828
+ // expected-error@-3 {{incomplete type 'CStructIncomplete[2]' where a complete type is required}}
1829
+ // expected-note@#CStructIncomplete {{forward declaration of 'CStructIncomplete'}}
1830
+ static_assert (__is_layout_compatible (CStructIncomplete[], CStructIncomplete[]));
1831
+ static_assert (!__is_layout_compatible (CStructWithArrayAtTheEnd, CStructWithFMA));
1832
+ static_assert (__is_layout_compatible (CStructWithFMA, CStructWithFMA));
1833
+ static_assert (__is_layout_compatible (CStructWithFMA, CStructWithFMA2));
1834
+ // Layout compatibility rules for enums might be relaxed in the future. See https://github.com/cplusplus/CWG/issues/39#issuecomment-1184791364
1804
1835
static_assert (!__is_layout_compatible (EnumLayout, int ));
1805
1836
static_assert (!__is_layout_compatible (EnumClassLayout, int ));
1806
1837
static_assert (!__is_layout_compatible (EnumForward, int ));
1807
1838
static_assert (!__is_layout_compatible (EnumClassForward, int ));
1808
- // FIXME: the following should be rejected (array of unknown bound and void are the only allowed incomplete types)
1809
- static_assert (__is_layout_compatible (CStructIncomplete, CStructIncomplete));
1810
- static_assert (!__is_layout_compatible (CStruct, CStructIncomplete));
1811
- static_assert (__is_layout_compatible (CStructIncomplete[2 ], CStructIncomplete[2 ]));
1812
1839
}
1813
1840
1814
1841
void is_signed ()
0 commit comments