Naios / continuable

C++14 asynchronous allocation aware futures (supporting then, exception handling, coroutines and connections)
https://naios.github.io/continuable/
MIT License
815 stars 44 forks source link

MSVC 2019 build error in cti::detail::transforms::wait_relaxed() #51

Closed rkonklewski-am2m closed 1 year ago

rkonklewski-am2m commented 1 year ago

Hi, @Naios!

Found another one ;) MSVC 2019 seems to have a problem constructing cti::detail::transforms::unsafe_unlocker with initializer list syntax inside cti::detail::transforms::wait_relaxed().

To fix it, there needs be a constructor such as the following:

unsafe_unlocker(std::atomic_bool* ready, condition_variable_t* cv,
                std::mutex* mutex, Result* result)
  : ready_{ready}, cv_{cv}, mutex_{mutex}, result_{result} {}

Commit Hash

4.2.0 release

Expected Behavior

No build errors.

Actual Behavior

*redacted*\continuable\include\continuable\detail\transforms\wait.hpp(130): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'cti::detail::transforms::unsafe_unlocker<Result>'
          with
          [
              Result=cti::result<>
          ]
  *redacted*\continuable\include\continuable/detail/transforms/wait.hpp(135): note: No constructor could take the source type, or constructor overload resolution was ambiguous
  *redacted*\continuable\include\continuable/detail/transforms/wait.hpp(153): note: see reference to function template instantiation 'Result cti::detail::transforms::wait_relaxed<cti::detail::base::ready_continuation<>,cti::detail::identity<>,cti::result<>>(cti::continuable_base<cti::detail::base::ready_continuation<>,cti::detail::identity<>> &&)' being compiled
          with
          [
              Result=cti::result<>
          ]
  *redacted*\continuable\include\continuable/transforms/wait.hpp(78): note: see reference to function template instantiation 'void cti::detail::transforms::wait_and_unpack<cti::detail::base::ready_continuation<>,cti::detail::identity<>>(cti::continuable_base<cti::detail::base::ready_continuation<>,cti::detail::identity<>> &&)' being compiled
  *redacted*\continuable\include\continuable/continuable-base.hpp(480): note: see reference to function template instantiation 'void cti::transforms::wait::<lambda_1>::operator ()<Continuable>(_T1 &&) const' being compiled
          with
          [
              Continuable=cti::continuable_base<cti::detail::base::ready_continuation<>,cti::detail::identity<>>,
              _T1=cti::continuable_base<cti::detail::base::ready_continuation<>,cti::detail::identity<>>
          ]
  ..\..\..\continuable_test.cpp(43): note: see reference to function template instantiation 'void cti::continuable_base<cti::detail::base::ready_continuation<>,cti::detail::identity<>>::apply<cti::transforms::wait::<lambda_1>>(T &&) &&' being compiled
          with
          [
              T=cti::transforms::wait::<lambda_1>
          ]
*redacted*\continuable\include\continuable\detail\transforms\wait.hpp(130): error C2672: 'cti::continuable_base<cti::detail::base::ready_continuation<>,cti::detail::identity<>>::next': no matching overloaded function found

Steps to Reproduce

cti::make_ready_continuable().apply(cti::transforms::wait());

Your Environment

rkonklewski-am2m commented 1 year ago

I first thought it was a compiler bug, but it also reproduces with gcc 12.2, which is an entirely different compiler. See https://godbolt.org/z/KTd6qG3es

Naios commented 1 year ago

Thanks for your report, could you open a PR with your suggested fix?

rkonklewski-am2m commented 1 year ago

Done. I did some more digging. It was invalid C++20 syntax after all. Interestingly, it was valid C++17. C++20 changed the requirements for aggregate types.