sol2 icon indicating copy to clipboard operation
sol2 copied to clipboard

fatal error: no member named 'construct' in this->construct(std::forward<Args>(args)...);

Open Electromasta opened this issue 7 months ago • 6 comments

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?

Electromasta avatar Apr 21 '25 23:04 Electromasta

I see this error under Linux with clang-19, but not with gcc-14.

s13n avatar Apr 22 '25 20:04 s13n

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......

Electromasta avatar Apr 26 '25 13:04 Electromasta

same, fails with gcc15

trexxet avatar Apr 29 '25 18:04 trexxet

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?

wufhex avatar May 06 '25 03:05 wufhex

Tested and worked. Should someone make a PR?

It's already fixed on the main branch.

trexxet avatar May 06 '25 07:05 trexxet

It was also fixed for v3.5.0, but that release introduced another bug, which can be fixed by applying pull request #1676.

s13n avatar May 06 '25 09:05 s13n