From 03f37345b6a8bb3c7e1dfb5148acb6a7cf89d55e Mon Sep 17 00:00:00 2001 From: Bruno Iljazovic Date: Mon, 19 Feb 2024 11:52:36 +0100 Subject: [PATCH] Remove temporaries from co_awaited expressions. Summary: - some older gcc versions don't handle temporaries in co_awaited expressions correctly, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98401 Reviewers: ivica Reviewed By: ivica Subscribers: korina Differential Revision: https://repo.mireo.local/D27990 --- test/integration/cancellation.cpp | 10 +++++++--- test/integration/coroutine.cpp | 20 +++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/test/integration/cancellation.cpp b/test/integration/cancellation.cpp index 84a5fef..e1ad2d3 100644 --- a/test/integration/cancellation.cpp +++ b/test/integration/cancellation.cpp @@ -228,6 +228,7 @@ struct shared_test_data { const std::string topic = "topic"; const std::string payload = "payload"; + const publish_props pub_props; const std::string publish_qos1 = encoders::encode_publish( 1, topic, payload, qos_e::at_least_once, retain_e::no, dup_e::no, {} @@ -275,8 +276,11 @@ BOOST_FIXTURE_TEST_CASE(rerunning_the_client, shared_test_data) { c.brokers("127.0.0.1,127.0.0.1", 1883) // to avoid reconnect backoff .async_run(asio::detached); + // Note: Older versions of GCC compilers may not handle temporaries + // correctly in co_await expressions. + // (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98401) auto [ec, rc, props] = co_await c.async_publish( - topic, payload, retain_e::no, publish_props {}, use_nothrow_awaitable + topic, payload, retain_e::no, pub_props, use_nothrow_awaitable ); BOOST_TEST(!ec); BOOST_TEST(!rc); @@ -284,7 +288,7 @@ BOOST_FIXTURE_TEST_CASE(rerunning_the_client, shared_test_data) { c.cancel(); auto [cec, crc, cprops] = co_await c.async_publish( - topic, payload, retain_e::no, publish_props {}, use_nothrow_awaitable + topic, payload, retain_e::no, pub_props, use_nothrow_awaitable ); BOOST_TEST(cec == asio::error::operation_aborted); BOOST_TEST(crc == reason_codes::empty); @@ -292,7 +296,7 @@ BOOST_FIXTURE_TEST_CASE(rerunning_the_client, shared_test_data) { c.async_run(asio::detached); auto [rec, rrc, rprops] = co_await c.async_publish( - topic, payload, retain_e::no, publish_props {}, use_nothrow_awaitable + topic, payload, retain_e::no, pub_props, use_nothrow_awaitable ); BOOST_TEST(!rec); BOOST_TEST(!rrc); diff --git a/test/integration/coroutine.cpp b/test/integration/coroutine.cpp index 26d8696..eed675f 100644 --- a/test/integration/coroutine.cpp +++ b/test/integration/coroutine.cpp @@ -55,15 +55,19 @@ constexpr auto use_nothrow_awaitable = asio::as_tuple(asio::use_awaitable); template asio::awaitable sanity_check(mqtt_client& c) { + // Note: Older versions of GCC compilers may not handle temporaries + // correctly in co_await expressions. + // (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98401) + publish_props pub_props; auto [ec_0] = co_await c.template async_publish( - "test/mqtt-test", "hello world with qos0!", retain_e::yes, publish_props {}, + "test/mqtt-test", "hello world with qos0!", retain_e::yes, pub_props, use_nothrow_awaitable ); BOOST_TEST_WARN(!ec_0); auto [ec_1, puback_rc, puback_props] = co_await c.template async_publish( "test/mqtt-test", "hello world with qos1!", - retain_e::yes, publish_props {}, + retain_e::yes, pub_props, use_nothrow_awaitable ); BOOST_TEST_WARN(!ec_1); @@ -71,7 +75,7 @@ asio::awaitable sanity_check(mqtt_client& c) { auto [ec_2, pubcomp_rc, pubcomp_props] = co_await c.template async_publish( "test/mqtt-test", "hello world with qos2!", - retain_e::yes, publish_props {}, + retain_e::yes, pub_props, use_nothrow_awaitable ); BOOST_TEST_WARN(!ec_2); @@ -86,15 +90,17 @@ asio::awaitable sanity_check(mqtt_client& c) { } }; - auto [sub_ec, sub_codes, sub_props] = co_await c.async_subscribe( - sub_topic, subscribe_props {}, use_nothrow_awaitable + subscribe_props sub_props; + auto [sub_ec, sub_codes, suback_props] = co_await c.async_subscribe( + sub_topic, sub_props, use_nothrow_awaitable ); BOOST_TEST_WARN(!sub_ec); if (!sub_codes[0]) auto [rec, topic, payload, publish_props] = co_await c.async_receive(use_nothrow_awaitable); - auto [unsub_ec, unsub_codes, unsub_props] = co_await c.async_unsubscribe( - "test/mqtt-test", unsubscribe_props {}, + unsubscribe_props unsub_props; + auto [unsub_ec, unsub_codes, unsuback_props] = co_await c.async_unsubscribe( + "test/mqtt-test", unsub_props, use_nothrow_awaitable ); BOOST_TEST_WARN(!unsub_ec);