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 //===----------------------------------------------------------------------===//
11 // const T* data() const;
15 #include <cstddef> // for std::max_align_t
17 #include "test_macros.h"
19 // std::array is explicitly allowed to be initialized with A a = { init-list };.
20 // Disable the missing braces warning for this reason.
21 #include "disable_missing_braces_warning.h"
31 typedef std::array
<T
, 3> C
;
32 const C c
= {1, 2, 3.5};
33 const T
* p
= c
.data();
40 typedef std::array
<T
, 0> C
;
42 const T
* p
= c
.data();
43 (void)p
; // to placate scan-build
47 typedef std::array
<T
, 0> C
;
49 const T
* p
= c
.data();
50 LIBCPP_ASSERT(p
!= nullptr);
53 typedef std::max_align_t T
;
54 typedef std::array
<T
, 0> C
;
56 const T
* p
= c
.data();
57 LIBCPP_ASSERT(p
!= nullptr);
58 std::uintptr_t pint
= reinterpret_cast<std::uintptr_t>(p
);
59 assert(pint
% TEST_ALIGNOF(std::max_align_t
) == 0);
63 typedef std::array
<int, 5> C
;
64 constexpr C c1
{0,1,2,3,4};
65 constexpr const C c2
{0,1,2,3,4};
67 static_assert ( c1
.data() == &c1
[0], "");
68 static_assert ( *c1
.data() == c1
[0], "");
69 static_assert ( c2
.data() == &c2
[0], "");
70 static_assert ( *c2
.data() == c2
[0], "");