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// UNSUPPORTED: libcpp-no-exceptions 11// MODULES_DEFINES: _LIBCPP_DEBUG=1 12// MODULES_DEFINES: _LIBCPP_DEBUG_USE_EXCEPTIONS 13 14// Can't test the system lib because this test enables debug mode 15// UNSUPPORTED: with_system_cxx_lib 16 17// test array<T, 0>::operator[] throws a debug exception. 18 19#define _LIBCPP_DEBUG 1 20#define _LIBCPP_DEBUG_USE_EXCEPTIONS 21#include <array> 22 23template <class Array> 24inline bool CheckDebugThrows(Array& Arr, size_t Index) { 25 try { 26 Arr[Index]; 27 } catch (std::__libcpp_debug_exception const&) { 28 return true; 29 } 30 return false; 31} 32 33int main() 34{ 35 { 36 typedef std::array<int, 0> C; 37 C c = {}; 38 C const& cc = c; 39 assert(CheckDebugThrows(c, 0)); 40 assert(CheckDebugThrows(c, 1)); 41 assert(CheckDebugThrows(cc, 0)); 42 assert(CheckDebugThrows(cc, 1)); 43 } 44 { 45 typedef std::array<const int, 0> C; 46 C c = {{}}; 47 C const& cc = c; 48 assert(CheckDebugThrows(c, 0)); 49 assert(CheckDebugThrows(c, 1)); 50 assert(CheckDebugThrows(cc, 0)); 51 assert(CheckDebugThrows(cc, 1)); 52 } 53} 54