[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug c++/101027] Short-circuit behavior not respected with co_await in while head
From:       kiwixz at outlook dot com via Gcc-bugs <gcc-bugs () gcc ! gnu ! org>
Date:       2021-11-30 20:50:09
Message-ID: bug-101027-4-3hxi4S8AFF () http ! gcc ! gnu ! org/bugzilla/
[Download RAW message or body]

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101027

kiwixz at outlook dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kiwixz at outlook dot com

--- Comment #1 from kiwixz at outlook dot com ---
Hello, I encountered the same problem with gcc evaluating the two asio
coroutine operands of && even when the left one returned false.

See on godbolt: https://godbolt.org/z/Wo8z5PoP3

Expected output (confirmed on clang 12 with libc++):
a
0

GCC 11.2 or trunk:
a
b
0

---

#include <iostream>
#include <boost/asio.hpp>

namespace asio = boost::asio;

asio::awaitable<bool> a() {
    std::cout << "a\n";
    co_return false;
}

asio::awaitable<bool> b() {
    std::cout << "b\n";
    co_return false;
}

asio::awaitable<void> f() {
    std::cout << ((co_await a()) && (co_await b())) << "\n";
}

int main() {
    asio::io_context io;
    asio::co_spawn(io, f, asio::detached);
    io.run();
}=
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic