1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
18 #include <type_traits>
20 #include "test_macros.h"
22 int main(int, char**) {
23 static_assert(std::is_enum
<std::endian
>::value
, "");
25 // Check that E is a scoped enum by checking for conversions.
26 typedef std::underlying_type
<std::endian
>::type UT
;
27 static_assert(!std::is_convertible
<std::endian
, UT
>::value
, "");
29 // test that the enumeration values exist
30 static_assert( std::endian::little
== std::endian::little
);
31 static_assert( std::endian::big
== std::endian::big
);
32 static_assert( std::endian::native
== std::endian::native
);
33 static_assert( std::endian::little
!= std::endian::big
);
35 // Technically not required, but true on all existing machines
36 static_assert( std::endian::native
== std::endian::little
||
37 std::endian::native
== std::endian::big
);
39 // Try to check at runtime
41 std::uint32_t i
= 0x01020304;
43 static_assert(sizeof(i
) == sizeof(c
));
44 std::memcpy(c
, &i
, sizeof(c
));
46 assert ((c
[0] == 1) == (std::endian::native
== std::endian::big
));