mireo / async-mqtt5

A C++17 MQTT client based on Boost.Asio.
https://spacetime.mireo.com/async-mqtt5/
Boost Software License 1.0
154 stars 11 forks source link

Compilation errors GCC 9 #7

Closed amcharhal closed 6 months ago

amcharhal commented 6 months ago

I encountered numerous compilation errors when attempting to compile the example code you provided. Interestingly, it compiles without issues on other devices.

Here are the specifications of the host where the code fails to compile:

Ubuntu 20.04 GCC version 9.4.0 C++17 I noticed that you tested it only with GCC 10. While it should theoretically work with C++17, if any features from C++20 are utilized, it might cause compatibility problems

ksimicevic commented 6 months ago

Thanks for reporting the issue!

As it turns out, GCC in versions 9, 10 and 11 have inconsistent treatment of noexcept move constructors. Clang and MSVC are consistent. Here's a simplified description of the problem:

  struct A {
      A(A&&) = default;
  };

  struct B {
      A a;
      B(B&&) noexcept = default;
  };

GCC will throw a compile-time error since B marks its move constructor as noexcept while A does not. Hence, B's move constructor wouldn't throw, while A's may, which is inconsistent. Clang and MSVC compile the above code in all versions (although strictly speaking, they shouldn't), while GCC in different versions does different things. You may look for details in the proposal P1286R2.

In our particular case, the problem was that Asio's bind structures do not mark their move constructors with noexcept while we use noexcept for move constructors in classes having these bind structures as members. Therefore, we were also inconsistent.

The fix has already been pushed to the master branch.