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>
1659cdf90aSEric Fiselier #include "test_macros.h"
175a83710eSEric Fiselier 
18b4e2e7a2SEric Fiselier // std::array is explicitly allowed to be initialized with A a = { init-list };.
19b4e2e7a2SEric Fiselier // Disable the missing braces warning for this reason.
20b4e2e7a2SEric Fiselier #include "disable_missing_braces_warning.h"
212decfad7SEric Fiselier 
22*db49965aSMarshall Clow struct NoDefault {
23*db49965aSMarshall Clow   NoDefault(int) {}
24*db49965aSMarshall Clow };
25*db49965aSMarshall Clow 
26*db49965aSMarshall Clow 
275a83710eSEric Fiselier int main()
285a83710eSEric Fiselier {
295a83710eSEric Fiselier     {
305a83710eSEric Fiselier         typedef double T;
315a83710eSEric Fiselier         typedef std::array<T, 3> C;
325a83710eSEric Fiselier         C c = {1, 2, 3.5};
335a83710eSEric Fiselier         T* p = c.data();
345a83710eSEric Fiselier         assert(p[0] == 1);
355a83710eSEric Fiselier         assert(p[1] == 2);
365a83710eSEric Fiselier         assert(p[2] == 3.5);
375a83710eSEric Fiselier     }
385a83710eSEric Fiselier     {
395a83710eSEric Fiselier         typedef double T;
405a83710eSEric Fiselier         typedef std::array<T, 0> C;
415a83710eSEric Fiselier         C c = {};
425a83710eSEric Fiselier         T* p = c.data();
4359cdf90aSEric Fiselier         assert(p != nullptr);
4459cdf90aSEric Fiselier     }
4559cdf90aSEric Fiselier     {
4659cdf90aSEric Fiselier       typedef double T;
4759cdf90aSEric Fiselier       typedef std::array<const T, 0> C;
4859cdf90aSEric Fiselier       C c = {{}};
4959cdf90aSEric Fiselier       const T* p = c.data();
5059cdf90aSEric Fiselier       static_assert((std::is_same<decltype(c.data()), const T*>::value), "");
5159cdf90aSEric Fiselier       assert(p != nullptr);
5259cdf90aSEric Fiselier     }
5359cdf90aSEric Fiselier   {
5459cdf90aSEric Fiselier       typedef std::max_align_t T;
5559cdf90aSEric Fiselier       typedef std::array<T, 0> C;
5659cdf90aSEric Fiselier       const C c = {};
5759cdf90aSEric Fiselier       const T* p = c.data();
5859cdf90aSEric Fiselier       assert(p != nullptr);
5959cdf90aSEric Fiselier       std::uintptr_t pint = reinterpret_cast<std::uintptr_t>(p);
6059cdf90aSEric Fiselier       assert(pint % TEST_ALIGNOF(std::max_align_t) == 0);
6159cdf90aSEric Fiselier     }
6259cdf90aSEric Fiselier     {
6359cdf90aSEric Fiselier       typedef NoDefault T;
6459cdf90aSEric Fiselier       typedef std::array<T, 0> C;
6559cdf90aSEric Fiselier       C c = {};
6659cdf90aSEric Fiselier       T* p = c.data();
6759cdf90aSEric Fiselier       assert(p != nullptr);
685a83710eSEric Fiselier     }
695a83710eSEric Fiselier }
70