martinmoene / expected-lite

expected lite - Expected objects in C++11 and later in a single-file header-only library
Boost Software License 1.0
375 stars 34 forks source link

expected is now C++23 not C++20 #43

Closed bigerl closed 2 years ago

bigerl commented 2 years ago

After upgrading to libstdc++-12 I ran into an error with expected-lite.

/home/xxx/.conan/data/expected-lite/0.5.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/nonstd/expected.hpp:208:16: error: no member named 'expected' in namespace 'std'; did you mean 'unexpected'?
    using std::expected;
          ~~~~~^
/usr/bin/../lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/exception:109:8: note: 'unexpected' declared here
  void unexpected() __attribute__ ((__noreturn__));

I guess the code in expected-lite was written under the assumption that std::expected would be included into C++20 standard. However, it was not and will likely be added in C++23. libstdc++-12 seems to be among the first to implement it and activates it when compiling with C++23. When compiling as C++20 with g++-12, the macro #if nsel_CPP20_OR_GREATER && defined(__has_include ) is activated, although it shoudn't.

The expected header of libsdc++-12 uses the following macro to deactivate std::expected for C++ <20:

#if __cplusplus > 202002L && __cpp_concepts >= 202002L

Note: it uses > not <=

This 3-line patch should do the trick for me.

martinmoene commented 2 years ago

Thanks!

Hope to be able to have look at Conan within a few days.