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 main()22int main() 23 { 24 { 25 typedef double T; 26 typedef std::array<T, 3> C; 27 C c = {1, 2, 3.5}; 28 T* p = c.data(); 29 assert(p[0] == 1); 30 assert(p[1] == 2); 31 assert(p[2] == 3.5); 32 } 33 { 34 typedef double T; 35 typedef std::array<T, 0> C; 36 C c = {}; 37 T* p = c.data(); 38 assert(p != nullptr); 39 } 40 { 41 typedef double T; 42 typedef std::array<const T, 0> C; 43 C c = {{}}; 44 const T* p = c.data(); 45 static_assert((std::is_same<decltype(c.data()), const T*>::value), ""); 46 assert(p != nullptr); 47 } 48 { 49 typedef std::max_align_t T; 50 typedef std::array<T, 0> C; 51 const C c = {}; 52 const T* p = c.data(); 53 assert(p != nullptr); 54 std::uintptr_t pint = reinterpret_cast<std::uintptr_t>(p); 55 assert(pint % TEST_ALIGNOF(std::max_align_t) == 0); 56 } 57 { 58 struct NoDefault { 59 NoDefault(int) {} 60 }; 61 typedef NoDefault T; 62 typedef std::array<T, 0> C; 63 C c = {}; 64 T* p = c.data(); 65 assert(p != nullptr); 66 } 67 } 68