From a5672e0c4bd11a29cff908d9d61652c00aa1b6e3 Mon Sep 17 00:00:00 2001 From: Roger Ferrer Ibanez Date: Mon, 7 Nov 2016 08:23:59 +0000 Subject: [PATCH] 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 --- .../optional.object/optional.object.assign/copy.pass.cpp | 7 +++++-- .../optional.object/optional.object.assign/emplace.pass.cpp | 7 +++++-- .../emplace_initializer_list.pass.cpp | 7 +++++-- .../optional.object/optional.object.assign/move.pass.cpp | 11 +++++++---- .../optional.object/optional.object.ctor/const_T.pass.cpp | 7 +++++-- .../optional.object/optional.object.ctor/copy.pass.cpp | 13 +++++++++++-- .../optional.object.ctor/in_place_t.pass.cpp | 6 ++++-- .../optional.object.ctor/initializer_list.pass.cpp | 7 +++++-- .../optional.object/optional.object.ctor/move.pass.cpp | 13 +++++++++++-- .../optional.object/optional.object.ctor/rvalue_T.pass.cpp | 7 +++++-- .../optional.object/optional.object.observe/value.pass.cpp | 5 ++++- .../optional.object.observe/value_const.pass.cpp | 5 ++++- .../optional.object/optional.object.swap/swap.pass.cpp | 9 ++++++--- 13 files changed, 77 insertions(+), 27 deletions(-) diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/copy.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/copy.pass.cpp index ff37b22c..17ee975 100644 --- a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/copy.pass.cpp +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/copy.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11 -// XFAIL: libcpp-no-exceptions // // optional& operator=(const optional& rhs); @@ -17,6 +16,8 @@ #include #include +#include "test_macros.h" + using std::experimental::optional; struct AllowConstAssign { @@ -34,7 +35,7 @@ struct X X(const X&) { if (throw_now) - throw 6; + TEST_THROW(6); } }; @@ -79,6 +80,7 @@ int main() assert(static_cast(opt) == static_cast(opt2)); assert(*opt == *opt2); } +#ifndef TEST_HAS_NO_EXCEPTIONS { optional opt; optional opt2(X{}); @@ -95,4 +97,5 @@ int main() assert(static_cast(opt) == false); } } +#endif } diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace.pass.cpp index 6a7b56e..2563960 100644 --- a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace.pass.cpp +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11 -// XFAIL: libcpp-no-exceptions // // template void optional::emplace(Args&&... args); @@ -18,6 +17,8 @@ #include #include +#include "test_macros.h" + using std::experimental::optional; class X @@ -48,7 +49,7 @@ class Z public: static bool dtor_called; Z() = default; - Z(int) {throw 6;} + Z(int) {TEST_THROW(6);} ~Z() {dtor_called = true;} }; @@ -131,6 +132,7 @@ int main() assert(Y::dtor_called == true); } } +#ifndef TEST_HAS_NO_EXCEPTIONS { Z z; optional opt(z); @@ -147,4 +149,5 @@ int main() assert(Z::dtor_called == true); } } +#endif } diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp index b02616e..8a26580 100644 --- a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11 -// XFAIL: libcpp-no-exceptions // // template @@ -19,6 +18,8 @@ #include #include +#include "test_macros.h" + using std::experimental::optional; class X @@ -60,7 +61,7 @@ public: constexpr Z() : i_(0) {} constexpr Z(int i) : i_(i) {} Z(std::initializer_list il) : i_(il.begin()[0]), j_(il.begin()[1]) - {throw 6;} + {TEST_THROW(6);} ~Z() {dtor_called = true;} friend constexpr bool operator==(const Z& x, const Z& y) @@ -104,6 +105,7 @@ int main() assert(static_cast(opt) == true); assert(*opt == Y({1, 2})); } +#ifndef TEST_HAS_NO_EXCEPTIONS { Z z; optional opt(z); @@ -120,4 +122,5 @@ int main() assert(Z::dtor_called == true); } } +#endif } diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/move.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/move.pass.cpp index 1c3b780..4e2aca9 100644 --- a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/move.pass.cpp +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/move.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11 -// XFAIL: libcpp-no-exceptions // // optional& operator=(optional&& rhs) @@ -19,6 +18,8 @@ #include #include +#include "test_macros.h" + using std::experimental::optional; struct AllowConstAssign { @@ -36,7 +37,7 @@ struct X X(X&&) { if (throw_now) - throw 6; + TEST_THROW(6); } X& operator=(X&&) noexcept { @@ -44,10 +45,10 @@ struct X } }; -struct Y {}; - bool X::throw_now = false; +struct Y {}; + int main() { { @@ -88,6 +89,7 @@ int main() optional opt2; opt = std::move(opt2); } +#ifndef TEST_HAS_NO_EXCEPTIONS { static_assert(!std::is_nothrow_move_assignable>::value, ""); optional opt; @@ -105,6 +107,7 @@ int main() assert(static_cast(opt) == false); } } +#endif { static_assert(std::is_nothrow_move_assignable>::value, ""); } diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/const_T.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/const_T.pass.cpp index 9b6511a..6371dcb 100644 --- a/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/const_T.pass.cpp +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/const_T.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // // UNSUPPORTED: c++98, c++03, c++11 -// XFAIL: libcpp-no-exceptions // @@ -18,6 +17,8 @@ #include #include +#include "test_macros.h" + using std::experimental::optional; class X @@ -42,7 +43,7 @@ class Z { public: 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; try @@ -110,4 +112,5 @@ int main() assert(i == 6); } } +#endif } diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/copy.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/copy.pass.cpp index c7c687c..4b66fe80 100644 --- a/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/copy.pass.cpp +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/copy.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11 -// XFAIL: libcpp-no-exceptions // // optional(const optional& rhs); @@ -17,6 +16,8 @@ #include #include +#include "test_macros.h" + using std::experimental::optional; template @@ -24,7 +25,12 @@ void test(const optional& rhs, bool is_going_to_throw = false) { bool rhs_engaged = static_cast(rhs); +#ifdef TEST_HAS_NO_EXCEPTIONS + if (is_going_to_throw) + return; +#else try +#endif { optional lhs = rhs; assert(is_going_to_throw == false); @@ -32,10 +38,13 @@ test(const optional& rhs, bool is_going_to_throw = false) if (rhs_engaged) assert(*lhs == *rhs); } +#ifndef TEST_HAS_NO_EXCEPTIONS catch (int i) { assert(i == 6); + assert(is_going_to_throw); } +#endif } class X @@ -68,7 +77,7 @@ public: Z(const Z&) { if (++count == 2) - throw 6; + TEST_THROW(6); } friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;} diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/in_place_t.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/in_place_t.pass.cpp index dc1666b..6c2d71d 100644 --- a/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/in_place_t.pass.cpp +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/in_place_t.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // // UNSUPPORTED: c++98, c++03, c++11 -// XFAIL: libcpp-no-exceptions // @@ -19,6 +18,7 @@ #include #include +#include "test_macros.h" using std::experimental::optional; using std::experimental::in_place_t; @@ -55,7 +55,7 @@ public: class Z { public: - Z(int i) {throw 6;} + Z(int i) {TEST_THROW(6);} }; @@ -128,6 +128,7 @@ int main() }; } +#ifndef TEST_HAS_NO_EXCEPTIONS { try { @@ -139,4 +140,5 @@ int main() assert(i == 6); } } +#endif } diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/initializer_list.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/initializer_list.pass.cpp index 9bd6b18..b75c147 100644 --- a/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/initializer_list.pass.cpp +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/initializer_list.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11 -// XFAIL: libcpp-no-exceptions // // template @@ -20,6 +19,8 @@ #include #include +#include "test_macros.h" + using std::experimental::optional; using std::experimental::in_place_t; using std::experimental::in_place; @@ -60,7 +61,7 @@ public: constexpr Z() : i_(0) {} constexpr Z(int i) : i_(i) {} Z(std::initializer_list il) : i_(il.begin()[0]), j_(il.begin()[1]) - {throw 6;} + {TEST_THROW(6);} friend constexpr bool operator==(const Z& x, const Z& y) {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}); static_assert(*dopt == Y{42, 101, -1}, ""); } +#ifndef TEST_HAS_NO_EXCEPTIONS { static_assert(std::is_constructible, std::initializer_list&>::value, ""); try @@ -112,4 +114,5 @@ int main() assert(i == 6); } } +#endif } diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp index 4ed0c92..a8bb6e9 100644 --- a/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11 -// XFAIL: libcpp-no-exceptions // // optional(optional&& rhs) noexcept(is_nothrow_move_constructible::value); @@ -17,6 +16,8 @@ #include #include +#include "test_macros.h" + using std::experimental::optional; template @@ -26,16 +27,24 @@ test(optional& rhs, bool is_going_to_throw = false) static_assert(std::is_nothrow_move_constructible>::value == std::is_nothrow_move_constructible::value, ""); bool rhs_engaged = static_cast(rhs); +#ifdef TEST_HAS_NO_EXCEPTIONS + if (is_going_to_throw) + return; +#else try +#endif { optional lhs = std::move(rhs); assert(is_going_to_throw == false); assert(static_cast(lhs) == rhs_engaged); } +#ifndef TEST_HAS_NO_EXCEPTIONS catch (int i) { assert(i == 6); + assert(is_going_to_throw); } +#endif } class X @@ -68,7 +77,7 @@ public: Z(Z&&) { if (++count == 2) - throw 6; + TEST_THROW(6); } friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;} diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/rvalue_T.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/rvalue_T.pass.cpp index ef21fcd..1941546 100644 --- a/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/rvalue_T.pass.cpp +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.ctor/rvalue_T.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // // UNSUPPORTED: c++98, c++03, c++11 -// XFAIL: libcpp-no-exceptions // @@ -18,6 +17,8 @@ #include #include +#include "test_macros.h" + using std::experimental::optional; class X @@ -44,7 +45,7 @@ class Z { public: Z(int) {} - Z(Z&&) {throw 6;} + Z(Z&&) {TEST_THROW(6);} }; @@ -92,6 +93,7 @@ int main() constexpr test_constexpr_ctor(T&&) {} }; } +#ifndef TEST_HAS_NO_EXCEPTIONS { typedef Z T; try @@ -104,4 +106,5 @@ int main() assert(i == 6); } } +#endif } diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.observe/value.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.observe/value.pass.cpp index b998f30..c8f0711 100644 --- a/libcxx/test/std/experimental/optional/optional.object/optional.object.observe/value.pass.cpp +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.observe/value.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11 -// XFAIL: libcpp-no-exceptions // // T& optional::value(); @@ -17,6 +16,8 @@ #include #include +#include "test_macros.h" + using std::experimental::optional; using std::experimental::bad_optional_access; @@ -35,6 +36,7 @@ int main() opt.emplace(); assert(opt.value().test() == 4); } +#ifndef TEST_HAS_NO_EXCEPTIONS { optional opt; try @@ -46,4 +48,5 @@ int main() { } } +#endif } diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.observe/value_const.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.observe/value_const.pass.cpp index a38b1f9..98ff16e 100644 --- a/libcxx/test/std/experimental/optional/optional.object/optional.object.observe/value_const.pass.cpp +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.observe/value_const.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11 -// XFAIL: libcpp-no-exceptions // // constexpr const T& optional::value() const; @@ -17,6 +16,8 @@ #include #include +#include "test_macros.h" + using std::experimental::optional; using std::experimental::in_place_t; using std::experimental::in_place; @@ -40,6 +41,7 @@ int main() const optional opt(in_place); assert(opt.value().test() == 3); } +#ifndef TEST_HAS_NO_EXCEPTIONS { const optional opt; try @@ -51,4 +53,5 @@ int main() { } } +#endif } diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.swap/swap.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.swap/swap.pass.cpp index be0d1ef..07b1af9 100644 --- a/libcxx/test/std/experimental/optional/optional.object/optional.object.swap/swap.pass.cpp +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.swap/swap.pass.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11 -// XFAIL: libcpp-no-exceptions // // void swap(optional&) @@ -19,6 +18,8 @@ #include #include +#include "test_macros.h" + using std::experimental::optional; class X @@ -56,10 +57,10 @@ class Z int i_; public: 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 void swap(Z& x, Z& y) {throw 6;} + friend void swap(Z& x, Z& y) {TEST_THROW(6);} }; struct ConstSwappable { @@ -231,6 +232,7 @@ int main() assert(static_cast(opt2) == true); assert(*opt2 == 1); } +#ifndef TEST_HAS_NO_EXCEPTIONS { optional opt1; optional opt2; @@ -307,4 +309,5 @@ int main() assert(static_cast(opt2) == true); assert(*opt2 == 2); } +#endif } -- 2.7.4