1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // type_traits
10 
11 // is_standard_layout
12 
13 #include <type_traits>
14 #include "test_macros.h"
15 
16 template <class T>
test_is_standard_layout()17 void test_is_standard_layout()
18 {
19     static_assert( std::is_standard_layout<T>::value, "");
20     static_assert( std::is_standard_layout<const T>::value, "");
21     static_assert( std::is_standard_layout<volatile T>::value, "");
22     static_assert( std::is_standard_layout<const volatile T>::value, "");
23 #if TEST_STD_VER > 14
24     static_assert( std::is_standard_layout_v<T>, "");
25     static_assert( std::is_standard_layout_v<const T>, "");
26     static_assert( std::is_standard_layout_v<volatile T>, "");
27     static_assert( std::is_standard_layout_v<const volatile T>, "");
28 #endif
29 }
30 
31 template <class T>
test_is_not_standard_layout()32 void test_is_not_standard_layout()
33 {
34     static_assert(!std::is_standard_layout<T>::value, "");
35     static_assert(!std::is_standard_layout<const T>::value, "");
36     static_assert(!std::is_standard_layout<volatile T>::value, "");
37     static_assert(!std::is_standard_layout<const volatile T>::value, "");
38 #if TEST_STD_VER > 14
39     static_assert(!std::is_standard_layout_v<T>, "");
40     static_assert(!std::is_standard_layout_v<const T>, "");
41     static_assert(!std::is_standard_layout_v<volatile T>, "");
42     static_assert(!std::is_standard_layout_v<const volatile T>, "");
43 #endif
44 }
45 
46 template <class T1, class T2>
47 struct pair
48 {
49     T1 first;
50     T2 second;
51 };
52 
main(int,char **)53 int main(int, char**)
54 {
55     test_is_standard_layout<int> ();
56     test_is_standard_layout<int[3]> ();
57     test_is_standard_layout<pair<int, double> > ();
58 
59     test_is_not_standard_layout<int&> ();
60 
61   return 0;
62 }
63