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.24k stars 520 forks source link

compilation issue: no member named 'construct' #1611

Closed hsdk123 closed 4 months ago

hsdk123 commented 5 months ago

Hi, I'm seeing a new error in compilation:

In file included from D:/a/Light.vn-core/Light.vn-core/_deps/sol2/80081c33f3d3c0bc53deb21b682463e1ae98eef5/include\sol/sol.hpp:53:
In file included from D:/a/Light.vn-core/Light.vn-core/_deps/sol2/80081c33f3d3c0bc53deb21b682463e1ae98eef5/include\sol/stack.hpp:27:
In file included from D:/a/Light.vn-core/Light.vn-core/_deps/sol2/80081c33f3d3c0bc53deb21b682463e1ae98eef5/include\sol/trampoline.hpp:27:
In file included from D:/a/Light.vn-core/Light.vn-core/_deps/sol2/80081c33f3d3c0bc53deb21b682463e1ae98eef5/include\sol/types.hpp:28:
In file included from D:/a/Light.vn-core/Light.vn-core/_deps/sol2/80081c33f3d3c0bc53deb21b682463e1ae98eef5/include\sol/optional.hpp:33:

D:/a/Light.vn-core/Light.vn-core/_deps/sol2/80081c33f3d3c0bc53deb21b682463e1ae98eef5/include\sol/optional_implementation.hpp:2191:10: error: no member named 'construct' in 'optional<type-parameter-0-0 &>'

 2191 |                         this->construct(std::forward<Args>(args)...);

      |                         ~~~~  ^

1 error generated.

compiler: CMAKE_C_COMPILER: D:/a/Light.vn-core/Light.vn-core/emsdk/upstream/emscripten/emcc.bat

-- The CXX compiler identification is Clang 19.0.0
-- The C compiler identification is Clang 19.0.0
tukss commented 4 months ago

I'm getting the same error. Even a simple test program that just includes sol/sol.hpp fails with the same error on Clang 19 (current main) but compiles fine with version 18.1.6.

It boils down to the implementation of the emplace member function in class optional. https://github.com/ThePhD/sol2/blob/e8e122e9ce46f4f1c0b04003d8b703fe1b89755a/include/sol/optional_implementation.hpp#L2189

At first glance it's strange why this ever worked. The construct member function is not part of optional.

Some further tests show that clang < 19 doesn't actually test for the existence of the member functions being called inside another member function of a templated type. Clang 19 changed that. This example might be instructive:

template<int i>
struct bar {
  void baz() {
    this->foo();
  }
};

int main(int argc, char**argv){

  bar<1> a;

  // uncommenting the code below makes it fail on every compiler
  // On clang >= 19 it even fails without the explicit call to baz but it works on g++ and clang < 19.
  //a.baz();

  return 0;
}

So I think this just worked before because emplace wasn't actually used. For my application I could get everything to work by just removing emplace entirely.

As a side note: The return type of emplace is T& but we don't actually return anything. This should probably be fixed as well.

tukss commented 4 months ago

1606 fixes it for me.

It seems that this-> doesn't resolve to m_value as it's suggested by operator overloading.

hsdk123 commented 4 months ago

Thanks @tukss! Hope the fix gets into main

hsdk123 commented 4 months ago

1606 merged - confirming issue resolved! Closing