[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / containers / sequences / array / array.data / data_const.pass.cpp
blobf6c2e594cc991ac8617ae6ebfcc4e71677bc3103
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // <array>
11 // const T* data() const;
13 #include <array>
14 #include <cassert>
15 #include <cstddef> // for std::max_align_t
16 #include <cstdint>
18 #include "test_macros.h"
20 struct NoDefault {
21 TEST_CONSTEXPR NoDefault(int) { }
24 #if TEST_STD_VER < 11
25 struct natural_alignment {
26 long t1;
27 long long t2;
28 double t3;
29 long double t4;
31 #endif
33 TEST_CONSTEXPR_CXX17 bool tests()
36 typedef double T;
37 typedef std::array<T, 3> C;
38 const C c = {1, 2, 3.5};
39 ASSERT_NOEXCEPT(c.data());
40 const T* p = c.data();
41 assert(p[0] == 1);
42 assert(p[1] == 2);
43 assert(p[2] == 3.5);
46 typedef double T;
47 typedef std::array<T, 0> C;
48 const C c = {};
49 ASSERT_NOEXCEPT(c.data());
50 const T* p = c.data();
51 (void)p;
54 typedef NoDefault T;
55 typedef std::array<T, 0> C;
56 const C c = {};
57 ASSERT_NOEXCEPT(c.data());
58 const T* p = c.data();
59 (void)p;
62 std::array<int, 5> const c = {0, 1, 2, 3, 4};
63 assert(c.data() == &c[0]);
64 assert(*c.data() == c[0]);
67 return true;
70 int main(int, char**)
72 tests();
73 #if TEST_STD_VER >= 17
74 static_assert(tests(), "");
75 #endif
77 // Test the alignment of data()
79 #if TEST_STD_VER < 11
80 typedef natural_alignment T;
81 #else
82 typedef std::max_align_t T;
83 #endif
84 typedef std::array<T, 0> C;
85 const C c = {};
86 const T* p = c.data();
87 std::uintptr_t pint = reinterpret_cast<std::uintptr_t>(p);
88 assert(pint % TEST_ALIGNOF(T) == 0);
91 return 0;