[libcxx] r286099 - Protect std::experimental::optional tests under libcpp-no-exceptions
Roger Ferrer Ibanez via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 7 00:24:00 PST 2016
Author: rogfer01
Date: Mon Nov 7 02:23:59 2016
New Revision: 286099
URL: http://llvm.org/viewvc/llvm-project?rev=286099&view=rev
Log:
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
Modified:
libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/copy.pass.cpp
libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/emplace.pass.cpp
libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp
libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/move.pass.cpp
libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/const_T.pass.cpp
libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/copy.pass.cpp
libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/in_place_t.pass.cpp
libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/initializer_list.pass.cpp
libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp
libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/rvalue_T.pass.cpp
libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.observe/value.pass.cpp
libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.observe/value_const.pass.cpp
libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.swap/swap.pass.cpp
Modified: libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/copy.pass.cpp?rev=286099&r1=286098&r2=286099&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/copy.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/copy.pass.cpp Mon Nov 7 02:23:59 2016
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
// optional<T>& operator=(const optional<T>& rhs);
@@ -17,6 +16,8 @@
#include <type_traits>
#include <cassert>
+#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<bool>(opt) == static_cast<bool>(opt2));
assert(*opt == *opt2);
}
+#ifndef TEST_HAS_NO_EXCEPTIONS
{
optional<X> opt;
optional<X> opt2(X{});
@@ -95,4 +97,5 @@ int main()
assert(static_cast<bool>(opt) == false);
}
}
+#endif
}
Modified: libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/emplace.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/emplace.pass.cpp?rev=286099&r1=286098&r2=286099&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/emplace.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/emplace.pass.cpp Mon Nov 7 02:23:59 2016
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
// template <class... Args> void optional<T>::emplace(Args&&... args);
@@ -18,6 +17,8 @@
#include <cassert>
#include <memory>
+#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<Z> opt(z);
@@ -147,4 +149,5 @@ int main()
assert(Z::dtor_called == true);
}
}
+#endif
}
Modified: libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp?rev=286099&r1=286098&r2=286099&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp Mon Nov 7 02:23:59 2016
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
// template <class U, class... Args>
@@ -19,6 +18,8 @@
#include <cassert>
#include <vector>
+#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<int> 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<bool>(opt) == true);
assert(*opt == Y({1, 2}));
}
+#ifndef TEST_HAS_NO_EXCEPTIONS
{
Z z;
optional<Z> opt(z);
@@ -120,4 +122,5 @@ int main()
assert(Z::dtor_called == true);
}
}
+#endif
}
Modified: libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/move.pass.cpp?rev=286099&r1=286098&r2=286099&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/move.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.assign/move.pass.cpp Mon Nov 7 02:23:59 2016
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
// optional<T>& operator=(optional<T>&& rhs)
@@ -19,6 +18,8 @@
#include <type_traits>
#include <cassert>
+#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<const AllowConstAssign> opt2;
opt = std::move(opt2);
}
+#ifndef TEST_HAS_NO_EXCEPTIONS
{
static_assert(!std::is_nothrow_move_assignable<optional<X>>::value, "");
optional<X> opt;
@@ -105,6 +107,7 @@ int main()
assert(static_cast<bool>(opt) == false);
}
}
+#endif
{
static_assert(std::is_nothrow_move_assignable<optional<Y>>::value, "");
}
Modified: libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/const_T.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/const_T.pass.cpp?rev=286099&r1=286098&r2=286099&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/const_T.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/const_T.pass.cpp Mon Nov 7 02:23:59 2016
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
@@ -18,6 +17,8 @@
#include <type_traits>
#include <cassert>
+#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
}
Modified: libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/copy.pass.cpp?rev=286099&r1=286098&r2=286099&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/copy.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/copy.pass.cpp Mon Nov 7 02:23:59 2016
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
// optional(const optional<T>& rhs);
@@ -17,6 +16,8 @@
#include <type_traits>
#include <cassert>
+#include "test_macros.h"
+
using std::experimental::optional;
template <class T>
@@ -24,7 +25,12 @@ void
test(const optional<T>& rhs, bool is_going_to_throw = false)
{
bool rhs_engaged = static_cast<bool>(rhs);
+#ifdef TEST_HAS_NO_EXCEPTIONS
+ if (is_going_to_throw)
+ return;
+#else
try
+#endif
{
optional<T> lhs = rhs;
assert(is_going_to_throw == false);
@@ -32,10 +38,13 @@ test(const optional<T>& rhs, bool is_goi
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_;}
Modified: libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/in_place_t.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/in_place_t.pass.cpp?rev=286099&r1=286098&r2=286099&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/in_place_t.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/in_place_t.pass.cpp Mon Nov 7 02:23:59 2016
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
@@ -19,6 +18,7 @@
#include <type_traits>
#include <cassert>
+#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
}
Modified: libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/initializer_list.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/initializer_list.pass.cpp?rev=286099&r1=286098&r2=286099&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/initializer_list.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/initializer_list.pass.cpp Mon Nov 7 02:23:59 2016
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
// template <class U, class... Args>
@@ -20,6 +19,8 @@
#include <vector>
#include <cassert>
+#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<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)
{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<optional<Z>, std::initializer_list<int>&>::value, "");
try
@@ -112,4 +114,5 @@ int main()
assert(i == 6);
}
}
+#endif
}
Modified: libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp?rev=286099&r1=286098&r2=286099&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/move.pass.cpp Mon Nov 7 02:23:59 2016
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
// optional(optional<T>&& rhs) noexcept(is_nothrow_move_constructible<T>::value);
@@ -17,6 +16,8 @@
#include <type_traits>
#include <cassert>
+#include "test_macros.h"
+
using std::experimental::optional;
template <class T>
@@ -26,16 +27,24 @@ test(optional<T>& rhs, bool is_going_to_
static_assert(std::is_nothrow_move_constructible<optional<T>>::value ==
std::is_nothrow_move_constructible<T>::value, "");
bool rhs_engaged = static_cast<bool>(rhs);
+#ifdef TEST_HAS_NO_EXCEPTIONS
+ if (is_going_to_throw)
+ return;
+#else
try
+#endif
{
optional<T> lhs = std::move(rhs);
assert(is_going_to_throw == false);
assert(static_cast<bool>(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_;}
Modified: libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/rvalue_T.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/rvalue_T.pass.cpp?rev=286099&r1=286098&r2=286099&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/rvalue_T.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.ctor/rvalue_T.pass.cpp Mon Nov 7 02:23:59 2016
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
@@ -18,6 +17,8 @@
#include <type_traits>
#include <cassert>
+#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
}
Modified: libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.observe/value.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.observe/value.pass.cpp?rev=286099&r1=286098&r2=286099&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.observe/value.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.observe/value.pass.cpp Mon Nov 7 02:23:59 2016
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
// T& optional<T>::value();
@@ -17,6 +16,8 @@
#include <type_traits>
#include <cassert>
+#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<X> opt;
try
@@ -46,4 +48,5 @@ int main()
{
}
}
+#endif
}
Modified: libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.observe/value_const.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.observe/value_const.pass.cpp?rev=286099&r1=286098&r2=286099&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.observe/value_const.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.observe/value_const.pass.cpp Mon Nov 7 02:23:59 2016
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
// constexpr const T& optional<T>::value() const;
@@ -17,6 +16,8 @@
#include <type_traits>
#include <cassert>
+#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<X> opt(in_place);
assert(opt.value().test() == 3);
}
+#ifndef TEST_HAS_NO_EXCEPTIONS
{
const optional<X> opt;
try
@@ -51,4 +53,5 @@ int main()
{
}
}
+#endif
}
Modified: libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.swap/swap.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.swap/swap.pass.cpp?rev=286099&r1=286098&r2=286099&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.swap/swap.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/optional/optional.object/optional.object.swap/swap.pass.cpp Mon Nov 7 02:23:59 2016
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11
-// XFAIL: libcpp-no-exceptions
// <optional>
// void swap(optional&)
@@ -19,6 +18,8 @@
#include <type_traits>
#include <cassert>
+#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<bool>(opt2) == true);
assert(*opt2 == 1);
}
+#ifndef TEST_HAS_NO_EXCEPTIONS
{
optional<Z> opt1;
optional<Z> opt2;
@@ -307,4 +309,5 @@ int main()
assert(static_cast<bool>(opt2) == true);
assert(*opt2 == 2);
}
+#endif
}
More information about the cfe-commits
mailing list