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>::front() 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) {
25  try {
26    Arr.back();
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));
40    assert(CheckDebugThrows(cc));
41  }
42  {
43    typedef std::array<const int, 0> C;
44    C c = {{}};
45    C const& cc = c;
46    assert(CheckDebugThrows(c));
47    assert(CheckDebugThrows(cc));
48  }
49}
50