Mark de Wever da79d6e177 [libc++][test] Uses qualified std::uint32_t.
The module std does not provide c-types in the global namespace. This
means all these types need to be fully qualified. This is a first step
to convert them by using sed.

Since this is an automated conversion other types like uint64_t are kept
as is.

Note that tests in the directory libcxx/test/std/depr/depr.c.headers
should not be converted automatically. This requires manual attention,
there some test require testing uint32_t in the global namespace. These
test should fail when using the std module, and pass when using the
std.compat module.

A similar issue occurs with atomic, atomic_uint32_t is specified as
  using atomic_uint32_t = atomic<uint32_t>; // freestanding
So here too we need to keep the name in the global namespace in the
tests.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D145520
2023-03-08 17:05:16 +01:00

51 lines
1.5 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// enum class endian;
// <bit>
#include <bit>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <type_traits>
#include "test_macros.h"
int main(int, char**) {
static_assert(std::is_enum<std::endian>::value, "");
// Check that E is a scoped enum by checking for conversions.
typedef std::underlying_type<std::endian>::type UT;
static_assert(!std::is_convertible<std::endian, UT>::value, "");
// test that the enumeration values exist
static_assert( std::endian::little == std::endian::little );
static_assert( std::endian::big == std::endian::big );
static_assert( std::endian::native == std::endian::native );
static_assert( std::endian::little != std::endian::big );
// Technically not required, but true on all existing machines
static_assert( std::endian::native == std::endian::little ||
std::endian::native == std::endian::big );
// Try to check at runtime
{
std::uint32_t i = 0x01020304;
char c[4];
static_assert(sizeof(i) == sizeof(c));
std::memcpy(c, &i, sizeof(c));
assert ((c[0] == 1) == (std::endian::native == std::endian::big));
}
return 0;
}