Protect std::experimental::optional tests under libcpp-no-exceptions

In these tests there are some paths that explicitly throw, so use
the TEST_THROW macro that was proposed for this and then skip the tests
that may enter the throwing path.

Differential Revision: https://reviews.llvm.org/D26142

llvm-svn: 286099
This commit is contained in:
Roger Ferrer Ibanez 2016-11-07 08:23:59 +00:00
parent 420537fad8
commit a5672e0c4b
13 changed files with 77 additions and 27 deletions

View File

@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11 // UNSUPPORTED: c++98, c++03, c++11
// XFAIL: libcpp-no-exceptions
// <optional> // <optional>
// optional<T>& operator=(const optional<T>& rhs); // optional<T>& operator=(const optional<T>& rhs);
@ -17,6 +16,8 @@
#include <type_traits> #include <type_traits>
#include <cassert> #include <cassert>
#include "test_macros.h"
using std::experimental::optional; using std::experimental::optional;
struct AllowConstAssign { struct AllowConstAssign {
@ -34,7 +35,7 @@ struct X
X(const X&) X(const X&)
{ {
if (throw_now) if (throw_now)
throw 6; TEST_THROW(6);
} }
}; };
@ -79,6 +80,7 @@ int main()
assert(static_cast<bool>(opt) == static_cast<bool>(opt2)); assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
assert(*opt == *opt2); assert(*opt == *opt2);
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
{ {
optional<X> opt; optional<X> opt;
optional<X> opt2(X{}); optional<X> opt2(X{});
@ -95,4 +97,5 @@ int main()
assert(static_cast<bool>(opt) == false); assert(static_cast<bool>(opt) == false);
} }
} }
#endif
} }

View File

@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11 // UNSUPPORTED: c++98, c++03, c++11
// XFAIL: libcpp-no-exceptions
// <optional> // <optional>
// template <class... Args> void optional<T>::emplace(Args&&... args); // template <class... Args> void optional<T>::emplace(Args&&... args);
@ -18,6 +17,8 @@
#include <cassert> #include <cassert>
#include <memory> #include <memory>
#include "test_macros.h"
using std::experimental::optional; using std::experimental::optional;
class X class X
@ -48,7 +49,7 @@ class Z
public: public:
static bool dtor_called; static bool dtor_called;
Z() = default; Z() = default;
Z(int) {throw 6;} Z(int) {TEST_THROW(6);}
~Z() {dtor_called = true;} ~Z() {dtor_called = true;}
}; };
@ -131,6 +132,7 @@ int main()
assert(Y::dtor_called == true); assert(Y::dtor_called == true);
} }
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
{ {
Z z; Z z;
optional<Z> opt(z); optional<Z> opt(z);
@ -147,4 +149,5 @@ int main()
assert(Z::dtor_called == true); assert(Z::dtor_called == true);
} }
} }
#endif
} }

View File

@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11 // UNSUPPORTED: c++98, c++03, c++11
// XFAIL: libcpp-no-exceptions
// <optional> // <optional>
// template <class U, class... Args> // template <class U, class... Args>
@ -19,6 +18,8 @@
#include <cassert> #include <cassert>
#include <vector> #include <vector>
#include "test_macros.h"
using std::experimental::optional; using std::experimental::optional;
class X class X
@ -60,7 +61,7 @@ public:
constexpr Z() : i_(0) {} constexpr Z() : i_(0) {}
constexpr Z(int i) : i_(i) {} constexpr Z(int i) : i_(i) {}
Z(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1]) Z(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1])
{throw 6;} {TEST_THROW(6);}
~Z() {dtor_called = true;} ~Z() {dtor_called = true;}
friend constexpr bool operator==(const Z& x, const Z& y) friend constexpr bool operator==(const Z& x, const Z& y)
@ -104,6 +105,7 @@ int main()
assert(static_cast<bool>(opt) == true); assert(static_cast<bool>(opt) == true);
assert(*opt == Y({1, 2})); assert(*opt == Y({1, 2}));
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
{ {
Z z; Z z;
optional<Z> opt(z); optional<Z> opt(z);
@ -120,4 +122,5 @@ int main()
assert(Z::dtor_called == true); assert(Z::dtor_called == true);
} }
} }
#endif
} }

View File

@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11 // UNSUPPORTED: c++98, c++03, c++11
// XFAIL: libcpp-no-exceptions
// <optional> // <optional>
// optional<T>& operator=(optional<T>&& rhs) // optional<T>& operator=(optional<T>&& rhs)
@ -19,6 +18,8 @@
#include <type_traits> #include <type_traits>
#include <cassert> #include <cassert>
#include "test_macros.h"
using std::experimental::optional; using std::experimental::optional;
struct AllowConstAssign { struct AllowConstAssign {
@ -36,7 +37,7 @@ struct X
X(X&&) X(X&&)
{ {
if (throw_now) if (throw_now)
throw 6; TEST_THROW(6);
} }
X& operator=(X&&) noexcept X& operator=(X&&) noexcept
{ {
@ -44,10 +45,10 @@ struct X
} }
}; };
struct Y {};
bool X::throw_now = false; bool X::throw_now = false;
struct Y {};
int main() int main()
{ {
{ {
@ -88,6 +89,7 @@ int main()
optional<const AllowConstAssign> opt2; optional<const AllowConstAssign> opt2;
opt = std::move(opt2); opt = std::move(opt2);
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
{ {
static_assert(!std::is_nothrow_move_assignable<optional<X>>::value, ""); static_assert(!std::is_nothrow_move_assignable<optional<X>>::value, "");
optional<X> opt; optional<X> opt;
@ -105,6 +107,7 @@ int main()
assert(static_cast<bool>(opt) == false); assert(static_cast<bool>(opt) == false);
} }
} }
#endif
{ {
static_assert(std::is_nothrow_move_assignable<optional<Y>>::value, ""); static_assert(std::is_nothrow_move_assignable<optional<Y>>::value, "");
} }

View File

@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// //
// UNSUPPORTED: c++98, c++03, c++11 // UNSUPPORTED: c++98, c++03, c++11
// XFAIL: libcpp-no-exceptions
// <optional> // <optional>
@ -18,6 +17,8 @@
#include <type_traits> #include <type_traits>
#include <cassert> #include <cassert>
#include "test_macros.h"
using std::experimental::optional; using std::experimental::optional;
class X class X
@ -42,7 +43,7 @@ class Z
{ {
public: public:
Z(int) {} Z(int) {}
Z(const Z&) {throw 6;} Z(const Z&) {TEST_THROW(6);}
}; };
@ -97,6 +98,7 @@ int main()
}; };
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
{ {
typedef Z T; typedef Z T;
try try
@ -110,4 +112,5 @@ int main()
assert(i == 6); assert(i == 6);
} }
} }
#endif
} }

View File

@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11 // UNSUPPORTED: c++98, c++03, c++11
// XFAIL: libcpp-no-exceptions
// <optional> // <optional>
// optional(const optional<T>& rhs); // optional(const optional<T>& rhs);
@ -17,6 +16,8 @@
#include <type_traits> #include <type_traits>
#include <cassert> #include <cassert>
#include "test_macros.h"
using std::experimental::optional; using std::experimental::optional;
template <class T> template <class T>
@ -24,7 +25,12 @@ void
test(const optional<T>& rhs, bool is_going_to_throw = false) test(const optional<T>& rhs, bool is_going_to_throw = false)
{ {
bool rhs_engaged = static_cast<bool>(rhs); bool rhs_engaged = static_cast<bool>(rhs);
#ifdef TEST_HAS_NO_EXCEPTIONS
if (is_going_to_throw)
return;
#else
try try
#endif
{ {
optional<T> lhs = rhs; optional<T> lhs = rhs;
assert(is_going_to_throw == false); assert(is_going_to_throw == false);
@ -32,10 +38,13 @@ test(const optional<T>& rhs, bool is_going_to_throw = false)
if (rhs_engaged) if (rhs_engaged)
assert(*lhs == *rhs); assert(*lhs == *rhs);
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
catch (int i) catch (int i)
{ {
assert(i == 6); assert(i == 6);
assert(is_going_to_throw);
} }
#endif
} }
class X class X
@ -68,7 +77,7 @@ public:
Z(const Z&) Z(const Z&)
{ {
if (++count == 2) if (++count == 2)
throw 6; TEST_THROW(6);
} }
friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;} friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;}

View File

@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// //
// UNSUPPORTED: c++98, c++03, c++11 // UNSUPPORTED: c++98, c++03, c++11
// XFAIL: libcpp-no-exceptions
// <optional> // <optional>
@ -19,6 +18,7 @@
#include <type_traits> #include <type_traits>
#include <cassert> #include <cassert>
#include "test_macros.h"
using std::experimental::optional; using std::experimental::optional;
using std::experimental::in_place_t; using std::experimental::in_place_t;
@ -55,7 +55,7 @@ public:
class Z class Z
{ {
public: public:
Z(int i) {throw 6;} Z(int i) {TEST_THROW(6);}
}; };
@ -128,6 +128,7 @@ int main()
}; };
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
{ {
try try
{ {
@ -139,4 +140,5 @@ int main()
assert(i == 6); assert(i == 6);
} }
} }
#endif
} }

View File

@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11 // UNSUPPORTED: c++98, c++03, c++11
// XFAIL: libcpp-no-exceptions
// <optional> // <optional>
// template <class U, class... Args> // template <class U, class... Args>
@ -20,6 +19,8 @@
#include <vector> #include <vector>
#include <cassert> #include <cassert>
#include "test_macros.h"
using std::experimental::optional; using std::experimental::optional;
using std::experimental::in_place_t; using std::experimental::in_place_t;
using std::experimental::in_place; using std::experimental::in_place;
@ -60,7 +61,7 @@ public:
constexpr Z() : i_(0) {} constexpr Z() : i_(0) {}
constexpr Z(int i) : i_(i) {} constexpr Z(int i) : i_(i) {}
Z(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1]) Z(std::initializer_list<int> il) : i_(il.begin()[0]), j_(il.begin()[1])
{throw 6;} {TEST_THROW(6);}
friend constexpr bool operator==(const Z& x, const Z& y) friend constexpr bool operator==(const Z& x, const Z& y)
{return x.i_ == y.i_ && x.j_ == y.j_;} {return x.i_ == y.i_ && x.j_ == y.j_;}
@ -100,6 +101,7 @@ int main()
constexpr test_constexpr_ctor dopt(in_place, {42, 101, -1}); constexpr test_constexpr_ctor dopt(in_place, {42, 101, -1});
static_assert(*dopt == Y{42, 101, -1}, ""); static_assert(*dopt == Y{42, 101, -1}, "");
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
{ {
static_assert(std::is_constructible<optional<Z>, std::initializer_list<int>&>::value, ""); static_assert(std::is_constructible<optional<Z>, std::initializer_list<int>&>::value, "");
try try
@ -112,4 +114,5 @@ int main()
assert(i == 6); assert(i == 6);
} }
} }
#endif
} }

View File

@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11 // UNSUPPORTED: c++98, c++03, c++11
// XFAIL: libcpp-no-exceptions
// <optional> // <optional>
// optional(optional<T>&& rhs) noexcept(is_nothrow_move_constructible<T>::value); // optional(optional<T>&& rhs) noexcept(is_nothrow_move_constructible<T>::value);
@ -17,6 +16,8 @@
#include <type_traits> #include <type_traits>
#include <cassert> #include <cassert>
#include "test_macros.h"
using std::experimental::optional; using std::experimental::optional;
template <class T> template <class T>
@ -26,16 +27,24 @@ test(optional<T>& rhs, bool is_going_to_throw = false)
static_assert(std::is_nothrow_move_constructible<optional<T>>::value == static_assert(std::is_nothrow_move_constructible<optional<T>>::value ==
std::is_nothrow_move_constructible<T>::value, ""); std::is_nothrow_move_constructible<T>::value, "");
bool rhs_engaged = static_cast<bool>(rhs); bool rhs_engaged = static_cast<bool>(rhs);
#ifdef TEST_HAS_NO_EXCEPTIONS
if (is_going_to_throw)
return;
#else
try try
#endif
{ {
optional<T> lhs = std::move(rhs); optional<T> lhs = std::move(rhs);
assert(is_going_to_throw == false); assert(is_going_to_throw == false);
assert(static_cast<bool>(lhs) == rhs_engaged); assert(static_cast<bool>(lhs) == rhs_engaged);
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
catch (int i) catch (int i)
{ {
assert(i == 6); assert(i == 6);
assert(is_going_to_throw);
} }
#endif
} }
class X class X
@ -68,7 +77,7 @@ public:
Z(Z&&) Z(Z&&)
{ {
if (++count == 2) if (++count == 2)
throw 6; TEST_THROW(6);
} }
friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;} friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;}

View File

@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// //
// UNSUPPORTED: c++98, c++03, c++11 // UNSUPPORTED: c++98, c++03, c++11
// XFAIL: libcpp-no-exceptions
// <optional> // <optional>
@ -18,6 +17,8 @@
#include <type_traits> #include <type_traits>
#include <cassert> #include <cassert>
#include "test_macros.h"
using std::experimental::optional; using std::experimental::optional;
class X class X
@ -44,7 +45,7 @@ class Z
{ {
public: public:
Z(int) {} Z(int) {}
Z(Z&&) {throw 6;} Z(Z&&) {TEST_THROW(6);}
}; };
@ -92,6 +93,7 @@ int main()
constexpr test_constexpr_ctor(T&&) {} constexpr test_constexpr_ctor(T&&) {}
}; };
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
{ {
typedef Z T; typedef Z T;
try try
@ -104,4 +106,5 @@ int main()
assert(i == 6); assert(i == 6);
} }
} }
#endif
} }

View File

@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11 // UNSUPPORTED: c++98, c++03, c++11
// XFAIL: libcpp-no-exceptions
// <optional> // <optional>
// T& optional<T>::value(); // T& optional<T>::value();
@ -17,6 +16,8 @@
#include <type_traits> #include <type_traits>
#include <cassert> #include <cassert>
#include "test_macros.h"
using std::experimental::optional; using std::experimental::optional;
using std::experimental::bad_optional_access; using std::experimental::bad_optional_access;
@ -35,6 +36,7 @@ int main()
opt.emplace(); opt.emplace();
assert(opt.value().test() == 4); assert(opt.value().test() == 4);
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
{ {
optional<X> opt; optional<X> opt;
try try
@ -46,4 +48,5 @@ int main()
{ {
} }
} }
#endif
} }

View File

@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11 // UNSUPPORTED: c++98, c++03, c++11
// XFAIL: libcpp-no-exceptions
// <optional> // <optional>
// constexpr const T& optional<T>::value() const; // constexpr const T& optional<T>::value() const;
@ -17,6 +16,8 @@
#include <type_traits> #include <type_traits>
#include <cassert> #include <cassert>
#include "test_macros.h"
using std::experimental::optional; using std::experimental::optional;
using std::experimental::in_place_t; using std::experimental::in_place_t;
using std::experimental::in_place; using std::experimental::in_place;
@ -40,6 +41,7 @@ int main()
const optional<X> opt(in_place); const optional<X> opt(in_place);
assert(opt.value().test() == 3); assert(opt.value().test() == 3);
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
{ {
const optional<X> opt; const optional<X> opt;
try try
@ -51,4 +53,5 @@ int main()
{ {
} }
} }
#endif
} }

View File

@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11 // UNSUPPORTED: c++98, c++03, c++11
// XFAIL: libcpp-no-exceptions
// <optional> // <optional>
// void swap(optional&) // void swap(optional&)
@ -19,6 +18,8 @@
#include <type_traits> #include <type_traits>
#include <cassert> #include <cassert>
#include "test_macros.h"
using std::experimental::optional; using std::experimental::optional;
class X class X
@ -56,10 +57,10 @@ class Z
int i_; int i_;
public: public:
Z(int i) : i_(i) {} Z(int i) : i_(i) {}
Z(Z&&) {throw 7;} Z(Z&&) {TEST_THROW(7);}
friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;} friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;}
friend void swap(Z& x, Z& y) {throw 6;} friend void swap(Z& x, Z& y) {TEST_THROW(6);}
}; };
struct ConstSwappable { struct ConstSwappable {
@ -231,6 +232,7 @@ int main()
assert(static_cast<bool>(opt2) == true); assert(static_cast<bool>(opt2) == true);
assert(*opt2 == 1); assert(*opt2 == 1);
} }
#ifndef TEST_HAS_NO_EXCEPTIONS
{ {
optional<Z> opt1; optional<Z> opt1;
optional<Z> opt2; optional<Z> opt2;
@ -307,4 +309,5 @@ int main()
assert(static_cast<bool>(opt2) == true); assert(static_cast<bool>(opt2) == true);
assert(*opt2 == 2); assert(*opt2 == 2);
} }
#endif
} }