llvm/llvm-project

[coroutine] Clang gives incorrect warnings

debashish-ghosh opened this issue · 4 comments

In the following code snippet:

#include <coroutine>
struct coro {
  struct promise_type {
    coro get_return_object();
    constexpr auto initial_suspend() { return std::suspend_never{}; }
    constexpr auto final_suspend() noexcept { return std::suspend_always{}; }
    void unhandled_exception();
    void return_void();
  };
};
coro c(int i) {
  co_await (i = 0, std::suspend_always{});
}

clang gives a weird warning:

warning: multiple unsequenced modifications to 'i' [-Wunsequenced]
  co_await (i = 1, std::suspend_always());
              ^
1 warning generated.

Another example can be found here.

It looks like this is caused by https://reviews.llvm.org/D115187 df2a4ea

the fix will be to skip CoroutineSuspendExpr in SemaChecking/CheckUnsequencedOperations, like we do in AnalyzeImplicitConversions.

We observe what we think is the same issue when doing, eg,

co_await foo(attempts++)