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