From 6914c81743154f31cda6152c695a1cb832a83426 Mon Sep 17 00:00:00 2001 From: Yannic Bonenberger Date: Fri, 15 May 2020 13:55:18 +0200 Subject: [PATCH] Re-add support for using Yoga without exceptions This is a partial rollback of 07c0d539bdb3a248762d0a06fd3f622b278a7ecb. --- tests/YGMeasureTest.cpp | 8 ++++++++ yoga/Utils.cpp | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/tests/YGMeasureTest.cpp b/tests/YGMeasureTest.cpp index e47607d44c..85b23ba5be 100644 --- a/tests/YGMeasureTest.cpp +++ b/tests/YGMeasureTest.cpp @@ -580,7 +580,11 @@ TEST(YogaDeathTest, cannot_add_child_to_node_with_measure_func) { root->setMeasureFunc(_measure); const YGNodeRef root_child0 = YGNodeNew(); +#if defined(__cpp_exceptions) ASSERT_THROW(YGNodeInsertChild(root, root_child0, 0), std::logic_error); +#else // !defined(__cpp_exceptions) + ASSERT_DEATH(YGNodeInsertChild(root, root_child0, 0), "Cannot add child.*"); +#endif // defined(__cpp_exceptions) YGNodeFree(root_child0); YGNodeFreeRecursive(root); } @@ -589,7 +593,11 @@ TEST(YogaDeathTest, cannot_add_nonnull_measure_func_to_non_leaf_node) { const YGNodeRef root = YGNodeNew(); const YGNodeRef root_child0 = YGNodeNew(); YGNodeInsertChild(root, root_child0, 0); +#if defined(__cpp_exceptions) ASSERT_THROW(root->setMeasureFunc(_measure), std::logic_error); +#else // !defined(__cpp_exceptions) + ASSERT_DEATH(root->setMeasureFunc(_measure), "Cannot set measure function.*"); +#endif // defined(__cpp_exceptions) YGNodeFreeRecursive(root); } diff --git a/yoga/Utils.cpp b/yoga/Utils.cpp index f6e55d0d8f..3c15552598 100644 --- a/yoga/Utils.cpp +++ b/yoga/Utils.cpp @@ -67,5 +67,9 @@ YGFloatOptional YGFloatOptionalMax(YGFloatOptional op1, YGFloatOptional op2) { } void throwLogicalErrorWithMessage(const char* message) { +#if defined(__cpp_exceptions) throw std::logic_error(message); +#else // !defined(__cpp_exceptions) + std::terminate(); +#endif // defined(__cpp_exceptions) }