sol2
sol2 copied to clipboard
fatal error: no member named 'construct' in this->construct(std::forward<Args>(args)...);
The latest released Sol version (3.3) and even the compiled (single file, 3.5) Sol version have the following issue:
./libs/sol/sol.hpp:5584:10: fatal error: no member named 'construct' in 'optional<type-parameter-0-0 &>' 5584 | this->construct(std::forward<Args>(args)...); | ~~~~ ^ 1 error generated. make: *** [Makefile:12: build] Error 1
I see the issue tracked here, but this syntax still appears in the file: https://github.com/ThePhD/sol2/commit/d805d027e0a0a7222e936926139f06e23828ce9f
My environment uses Msys/Mingw64 and the following clang: clang version 20.1.3 Target: x86_64-w64-windows-gnu Thread model: posix InstalledDir: C:/msys64/clang64/bin
Is this an Env issue or an issue with Sol?
I see this error under Linux with clang-19, but not with gcc-14.
I got this to work by switch out line 5584 for the following:
new (static_cast<void*>(this)) optional(std::in_place, std::forward<Args>(args)...);
return **this;
Then, Sol spits out a bunch of warnings if you have the compiler set to show them, those can be fixed by changing: template <typename R, typename... Args, typename F, typename = std::result_of_t<meta::unqualified_t<F>(Args...)>> to template <typename R, typename... Args, typename F, typename = std::invoke_result_t<meta::unqualified_t<F>(Args...)>>
in three different places......
same, fails with gcc15
Same with Clang 17. I fixed by replacing line 6755 from:
this->construct(std::forward<Args>(args)...);
to:
m_value = T(std::forward<Args>(args)...);
Tested and worked. Should someone make a PR?
Tested and worked. Should someone make a PR?
It's already fixed on the main branch.
It was also fixed for v3.5.0, but that release introduced another bug, which can be fixed by applying pull request #1676.