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 //===----------------------------------------------------------------------===//
15 #include <cstddef> // for std::max_align_t
18 #include "test_macros.h"
21 TEST_CONSTEXPR
NoDefault(int) { }
25 struct natural_alignment
{
33 TEST_CONSTEXPR_CXX17
bool tests()
37 typedef std::array
<T
, 3> C
;
39 ASSERT_NOEXCEPT(c
.data());
47 typedef std::array
<T
, 0> C
;
49 ASSERT_NOEXCEPT(c
.data());
55 typedef std::array
<const T
, 0> C
;
57 ASSERT_NOEXCEPT(c
.data());
58 const T
* p
= c
.data();
60 static_assert((std::is_same
<decltype(c
.data()), const T
*>::value
), "");
64 typedef std::array
<T
, 0> C
;
66 ASSERT_NOEXCEPT(c
.data());
71 std::array
<int, 5> c
= {0, 1, 2, 3, 4};
72 assert(c
.data() == &c
[0]);
73 assert(*c
.data() == c
[0]);
82 #if TEST_STD_VER >= 17
83 static_assert(tests(), "");
86 // Test the alignment of data()
89 typedef natural_alignment T
;
91 typedef std::max_align_t T
;
93 typedef std::array
<T
, 0> C
;
95 const T
* p
= c
.data();
96 std::uintptr_t pint
= reinterpret_cast<std::uintptr_t>(p
);
97 assert(pint
% TEST_ALIGNOF(T
) == 0);