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

            Bug ID: 110171
           Summary: [[nodiscard]] of await_resume ignored when discarding
                    result of co_await expression
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lukaslang.bugtracker at outlook dot com
  Target Milestone: ---

(Note: The example & bug is very similar to this here:
https://developercommunity.visualstudio.com/t/nodiscard-not-honored-by-co_await/1500944)

It seems that discarding the `co_await`ed result of an awaitable with
`[[nodiscard]]` `await_resume` doesn't lead to the expected warning
([Godbolt](https://godbolt.org/z/o47EdzMj8)):

```
#include <coroutine>

struct must_check_result
{
    bool await_ready() { return false; }
    void await_suspend(std::coroutine_handle<>) {}
    [[nodiscard]] bool await_resume() { return {}; }
};

struct task {};

namespace std
{
    template<typename... Args>
    struct coroutine_traits<task, Args...>
    {
        struct promise_type
        {
            task get_return_object() { return {}; }
            suspend_always initial_suspend() noexcept { return {}; }
            suspend_always final_suspend() noexcept { return {}; }
            void return_void() {}
            void unhandled_exception() {}
        };
    };
}

task example()
{
    co_await must_check_result(); // no warning even though await_ready is
marked [[nodiscard]]
    must_check_result().await_resume();
}
```

Reply via email to