1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <array>
11 
12 // T *data();
13 
14 #include <array>
15 #include <cassert>
16 #include "test_macros.h"
17 
18 // std::array is explicitly allowed to be initialized with A a = { init-list };.
19 // Disable the missing braces warning for this reason.
20 #include "disable_missing_braces_warning.h"
21 
22 struct NoDefault {
23   NoDefault(int) {}
24 };
25 
26 
27 int main()
28 {
29     {
30         typedef double T;
31         typedef std::array<T, 3> C;
32         C c = {1, 2, 3.5};
33         T* p = c.data();
34         assert(p[0] == 1);
35         assert(p[1] == 2);
36         assert(p[2] == 3.5);
37     }
38     {
39         typedef double T;
40         typedef std::array<T, 0> C;
41         C c = {};
42         T* p = c.data();
43         assert(p != nullptr);
44     }
45     {
46       typedef double T;
47       typedef std::array<const T, 0> C;
48       C c = {{}};
49       const T* p = c.data();
50       static_assert((std::is_same<decltype(c.data()), const T*>::value), "");
51       assert(p != nullptr);
52     }
53   {
54       typedef std::max_align_t T;
55       typedef std::array<T, 0> C;
56       const C c = {};
57       const T* p = c.data();
58       assert(p != nullptr);
59       std::uintptr_t pint = reinterpret_cast<std::uintptr_t>(p);
60       assert(pint % TEST_ALIGNOF(std::max_align_t) == 0);
61     }
62     {
63       typedef NoDefault T;
64       typedef std::array<T, 0> C;
65       C c = {};
66       T* p = c.data();
67       assert(p != nullptr);
68     }
69 }
70