15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
35a83710eSEric Fiselier //                     The LLVM Compiler Infrastructure
45a83710eSEric Fiselier //
55a83710eSEric Fiselier // This file is dual licensed under the MIT and the University of Illinois Open
65a83710eSEric Fiselier // Source Licenses. See LICENSE.TXT for details.
75a83710eSEric Fiselier //
85a83710eSEric Fiselier //===----------------------------------------------------------------------===//
95a83710eSEric Fiselier 
105a83710eSEric Fiselier // <array>
115a83710eSEric Fiselier 
125a83710eSEric Fiselier // T *data();
135a83710eSEric Fiselier 
145a83710eSEric Fiselier #include <array>
155a83710eSEric Fiselier #include <cassert>
16c019b30aSLouis Dionne #include <cstddef>       // for std::max_align_t
17c019b30aSLouis Dionne 
1859cdf90aSEric Fiselier #include "test_macros.h"
195a83710eSEric Fiselier 
20b4e2e7a2SEric Fiselier // std::array is explicitly allowed to be initialized with A a = { init-list };.
21b4e2e7a2SEric Fiselier // Disable the missing braces warning for this reason.
22b4e2e7a2SEric Fiselier #include "disable_missing_braces_warning.h"
232decfad7SEric Fiselier 
24db49965aSMarshall Clow struct NoDefault {
25db49965aSMarshall Clow   NoDefault(int) {}
26db49965aSMarshall Clow };
27db49965aSMarshall Clow 
28db49965aSMarshall Clow 
295a83710eSEric Fiselier int main()
305a83710eSEric Fiselier {
315a83710eSEric Fiselier     {
325a83710eSEric Fiselier         typedef double T;
335a83710eSEric Fiselier         typedef std::array<T, 3> C;
345a83710eSEric Fiselier         C c = {1, 2, 3.5};
355a83710eSEric Fiselier         T* p = c.data();
365a83710eSEric Fiselier         assert(p[0] == 1);
375a83710eSEric Fiselier         assert(p[1] == 2);
385a83710eSEric Fiselier         assert(p[2] == 3.5);
395a83710eSEric Fiselier     }
405a83710eSEric Fiselier     {
415a83710eSEric Fiselier         typedef double T;
425a83710eSEric Fiselier         typedef std::array<T, 0> C;
435a83710eSEric Fiselier         C c = {};
445a83710eSEric Fiselier         T* p = c.data();
45*26f01c46SLouis Dionne         LIBCPP_ASSERT(p != nullptr);
4659cdf90aSEric Fiselier     }
4759cdf90aSEric Fiselier     {
4859cdf90aSEric Fiselier       typedef double T;
4959cdf90aSEric Fiselier       typedef std::array<const T, 0> C;
5059cdf90aSEric Fiselier       C c = {{}};
5159cdf90aSEric Fiselier       const T* p = c.data();
5259cdf90aSEric Fiselier       static_assert((std::is_same<decltype(c.data()), const T*>::value), "");
53*26f01c46SLouis Dionne       LIBCPP_ASSERT(p != nullptr);
5459cdf90aSEric Fiselier     }
5559cdf90aSEric Fiselier   {
5659cdf90aSEric Fiselier       typedef std::max_align_t T;
5759cdf90aSEric Fiselier       typedef std::array<T, 0> C;
5859cdf90aSEric Fiselier       const C c = {};
5959cdf90aSEric Fiselier       const T* p = c.data();
60*26f01c46SLouis Dionne       LIBCPP_ASSERT(p != nullptr);
6159cdf90aSEric Fiselier       std::uintptr_t pint = reinterpret_cast<std::uintptr_t>(p);
6259cdf90aSEric Fiselier       assert(pint % TEST_ALIGNOF(std::max_align_t) == 0);
6359cdf90aSEric Fiselier     }
6459cdf90aSEric Fiselier     {
6559cdf90aSEric Fiselier       typedef NoDefault T;
6659cdf90aSEric Fiselier       typedef std::array<T, 0> C;
6759cdf90aSEric Fiselier       C c = {};
6859cdf90aSEric Fiselier       T* p = c.data();
69*26f01c46SLouis Dionne       LIBCPP_ASSERT(p != nullptr);
705a83710eSEric Fiselier     }
715a83710eSEric Fiselier }
72