ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.18k stars 515 forks source link

sol::optional does not support copy construction of non trivially copyable types with const modifier #1561

Open elsid opened 9 months ago

elsid commented 9 months ago

See https://godbolt.org/z/Ta85r4a7e. Basically the problem is in the use of placement new (C++ does not allow to use pointer to const for the address). There is std::construct_at for such cases. For example look how std::optional is implemented in the libc++:

https://github.com/llvm/llvm-project/blob/3791b3fca6eac5e403b91550ed0f774866cf3ede/libcxx/include/optional#L419 https://github.com/llvm/llvm-project/blob/3791b3fca6eac5e403b91550ed0f774866cf3ede/libcxx/include/__memory/construct_at.h#L49-L54 https://github.com/llvm/llvm-project/blob/3791b3fca6eac5e403b91550ed0f774866cf3ede/libcxx/include/__memory/voidify.h#L25