From 5286e11fb9896dc6274f83d1a211cb452180c76a Mon Sep 17 00:00:00 2001 From: tobias-loew Date: Fri, 12 Jan 2018 14:56:19 +0100 Subject: [PATCH 1/2] added test for BOOST_SCOPE_EXIT inside lambda added test for BOOST_SCOPE_EXIT inside lambda --- test/native.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/native.cpp b/test/native.cpp index 682e112..ec3f331 100644 --- a/test/native.cpp +++ b/test/native.cpp @@ -185,10 +185,42 @@ void test_capture_all(void) { #endif // lambdas } +void test_lambda(void) { + + { + int i = 0, j = 1; + auto foo = [&]() { + BOOST_SCOPE_EXIT( (&i) (&j) ) { + i = j = 2; // modify references + } + BOOST_SCOPE_EXIT_END + }; + foo(); + + BOOST_TEST(i == 2); + BOOST_TEST(j == 2); + } + + { + auto bar = [&]() { + int local_i = 0, local_j = 1; + BOOST_SCOPE_EXIT( (&local_i) (&local_j) ) { + local_i = local_j = 2; // modify references + } + BOOST_SCOPE_EXIT_END + + BOOST_TEST(local_i == 2); + BOOST_TEST(local_j == 2); + }; + bar(); + } +} + int main(void) { test_non_local(); test_types(); test_capture_all(); + test_lambda(); return boost::report_errors(); } From 24f4470f24968807c38d1ce5ba70087d1dea97db Mon Sep 17 00:00:00 2001 From: tobias-loew Date: Fri, 12 Jan 2018 14:58:21 +0100 Subject: [PATCH 2/2] changed variable name --- test/native.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/native.cpp b/test/native.cpp index ec3f331..de0bfe1 100644 --- a/test/native.cpp +++ b/test/native.cpp @@ -203,14 +203,14 @@ void test_lambda(void) { { auto bar = [&]() { - int local_i = 0, local_j = 1; - BOOST_SCOPE_EXIT( (&local_i) (&local_j) ) { - local_i = local_j = 2; // modify references + int i = 0, j = 1; + BOOST_SCOPE_EXIT( (&i) (&j) ) { + i = j = 2; // modify references } BOOST_SCOPE_EXIT_END - BOOST_TEST(local_i == 2); - BOOST_TEST(local_j == 2); + BOOST_TEST(i == 2); + BOOST_TEST(j == 2); }; bar(); }