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 // const T* data() const; 13 14 #include <array> 15 #include <cassert> 16 17 #include "test_macros.h" 18 19 // std::array is explicitly allowed to be initialized with A a = { init-list };. 20 // Disable the missing braces warning for this reason. 21 #include "disable_missing_braces_warning.h" 22 23 int main() 24 { 25 { 26 typedef double T; 27 typedef std::array<T, 3> C; 28 const C c = {1, 2, 3.5}; 29 const T* p = c.data(); 30 assert(p[0] == 1); 31 assert(p[1] == 2); 32 assert(p[2] == 3.5); 33 } 34 { 35 typedef double T; 36 typedef std::array<T, 0> C; 37 const C c = {}; 38 const T* p = c.data(); 39 (void)p; // to placate scan-build 40 } 41 { 42 struct NoDefault { 43 NoDefault(int) {} 44 }; 45 typedef NoDefault T; 46 typedef std::array<T, 0> C; 47 const C c = {}; 48 const T* p = c.data(); 49 assert(p != nullptr); 50 } 51 { 52 typedef std::max_align_t T; 53 typedef std::array<T, 0> C; 54 const C c = {}; 55 const T* p = c.data(); 56 assert(p != nullptr); 57 std::uintptr_t pint = reinterpret_cast<std::uintptr_t>(p); 58 assert(pint % TEST_ALIGNOF(std::max_align_t) == 0); 59 } 60 #if TEST_STD_VER > 14 61 { 62 typedef std::array<int, 5> C; 63 constexpr C c1{0,1,2,3,4}; 64 constexpr const C c2{0,1,2,3,4}; 65 66 static_assert ( c1.data() == &c1[0], ""); 67 static_assert ( *c1.data() == c1[0], ""); 68 static_assert ( c2.data() == &c2[0], ""); 69 static_assert ( *c2.data() == c2[0], ""); 70 } 71 #endif 72 } 73