Asiri Rathnayake cc2e93cff0 Make it possible to build a no-exceptions variant of libcxx.
Fixes a small omission in libcxx that prevents libcxx being built when
-DLIBCXX_ENABLE_EXCEPTIONS=0 is specified.

This patch adds XFAILS to all those tests that are currently failing
on the new -fno-exceptions library variant. Follow-up patches will
update the tests (progressively) to cope with the new library variant.

Change-Id: I4b801bd8d8e4fe7193df9e55f39f1f393a8ba81a

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@252598 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-10 11:41:22 +00:00

96 lines
2.4 KiB
C++

//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// XFAIL: libcpp-no-exceptions
// dynarray.overview
// const_reference at(size_type n) const;
// reference at(size_type n);
#include <__config>
#if _LIBCPP_STD_VER > 11
#include <experimental/dynarray>
#include <cassert>
#include <algorithm>
#include <complex>
#include <string>
using std::experimental::dynarray;
template <class T>
void dyn_at_fail ( dynarray<T> &dyn, size_t sz ) {
try { dyn.at (sz); }
catch (const std::out_of_range &) { return; }
assert ( false );
}
template <class T>
void dyn_at_fail_const ( const dynarray<T> &dyn, size_t sz ) {
try { dyn.at (sz); }
catch (const std::out_of_range &) { return; }
assert ( false );
}
template <class T>
void dyn_test_const ( const dynarray<T> &dyn, const std::initializer_list<T> &vals ) {
const T *data = dyn.data ();
auto it = vals.begin ();
for ( size_t i = 0; i < dyn.size(); ++i, ++it ) {
assert ( data + i == &dyn.at(i));
assert ( *it == dyn.at(i));
}
dyn_at_fail_const ( dyn, dyn.size ());
dyn_at_fail_const ( dyn, 2*dyn.size ());
dyn_at_fail_const ( dyn, size_t (-1));
}
template <class T>
void dyn_test ( dynarray<T> &dyn, const std::initializer_list<T> &vals ) {
T *data = dyn.data ();
auto it = vals.begin ();
for ( size_t i = 0; i < dyn.size(); ++i, ++it ) {
assert ( data + i == &dyn.at(i));
assert ( *it == dyn.at(i));
}
dyn_at_fail ( dyn, dyn.size ());
dyn_at_fail ( dyn, 2*dyn.size ());
dyn_at_fail ( dyn, size_t (-1));
}
template <class T>
void test ( std::initializer_list<T> vals ) {
typedef dynarray<T> dynA;
dynA d1 ( vals );
dyn_test ( d1, vals );
dyn_test_const ( d1, vals );
}
int main()
{
test ( { 1, 1, 2, 3, 5, 8 } );
test ( { 1., 1., 2., 3., 5., 8. } );
test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"),
std::string("5"), std::string("8")} );
test<int> ( {} );
test<std::complex<double>> ( {} );
test<std::string> ( {} );
}
#else
int main() {}
#endif