chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.73k stars 1.2k forks source link

asio/coroutine.hpp macros raise implicit fall-through warnings under Clang or MSVC #1341

Open nickhutchinson opened 11 months ago

nickhutchinson commented 11 months ago

Reproducible with Boost 1.82 and both Clang 16 and VS 2022.

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

struct C : boost::asio::coroutine {

  void operator()() {
    BOOST_ASIO_CORO_REENTER(*this) {
        BOOST_ASIO_CORO_YIELD std::cerr << 1 << std::endl;
        BOOST_ASIO_CORO_YIELD std::cerr << 3 << std::endl;
        BOOST_ASIO_CORO_YIELD std::cerr << 2 << std::endl;
    }
  }
};

Build with -std=c++17 -Wimplicit-fallthrough with Clang:

https://godbolt.org/z/1vjPqWbcj

<source>:7:5: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
    BOOST_ASIO_CORO_REENTER(*this) {
...

Build with /std:c++17 and warning C5262 enabled with MSVC:

https://godbolt.org/z/e43aezad5

<source>(8): warning C5262: implicit fall-through occurs here; are you missing a break statement? Use [[fallthrough]] when a break statement is intentionally omitted between cases
<source>(8): note: statement that may fall through is here
...