sol2: Compiler error starting in v3.2.2 with non-copyable user type

Hi,

After upgrading my sol2 version from v3.2.1 to v3.2.2 I started seeing a compile error which I traced it to commit 0e1aafe4d. It is preventing me from registering a callable whose return type is a const & to a non-copyable type (although the problem may well be more general than that). Below I provided all of the info that you might need, but let me know if you need anything else.

Environment:

  • Language: C++, -std=c++20
  • OS: Linux/Pop!_OS 20.10
  • Compiler: Clang trunk as of a couple weeks ago:
    $ clang++ --version
    clang version 12.0.0 (https://github.com/llvm/llvm-project.git 6c2ad4cf8758335e0896ba0540b21bbf6d239fbd)
    Target: x86_64-unknown-linux-gnu
    Thread model: posix
  • Stdlib: libstdc++ from gcc 10.2.0
  • sol2 compiler defines:
    • SOL_USING_CXX_LUA=1
    • SOL_CXX17_FEATURES=1
    • SOL_ALL_SAFETIES_ON=1
    • SOL_EXCEPTIONS_ALWAYS_UNSAFE=1
    • SOL_PRINT_ERRORS=0

Standalone Reproducer

struct no_copy_type {
  no_copy_type()                      = default;
  no_copy_type( no_copy_type const& ) = delete;
  no_copy_type( no_copy_type&& )      = default;
};

struct my_callable {
  no_copy_type const& operator()() const {
    static no_copy_type o;
    return o;
  }
};

void test() {
  auto st = sol::state{};
  st["AAA"] = my_callable{};  // compile error here!!
}

This is impacting me because some of my types are movable but not copyable, and I used to be able to register callables that return const & of one of those non-copyable types but can’t seem to anymore as of v3.2.2. Am I doing something wrong?

Compiler Error

/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/alloc_traits.h:514:4: error: no matching function for call to 'construct_at'
          std::construct_at(__p, std::forward<_Args>(__args)...);
          ^~~~~~~~~~~~~~~~~
../../extern/sol2/include/sol/stack_push.hpp:120:46: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<rn::lua::(anonymous namespace)::no_copy_type>>::construct<rn::lua::(anonymous namespace)::no_copy_type, const rn::lua::(anonymous namespace)::no_copy_type &>' requested here
                        std::allocator_traits<std::allocator<T>>::construct(alloc, obj, std::forward<Args>(args)...);
                                                                  ^
../../extern/sol2/include/sol/stack_push.hpp:127:11: note: in instantiation of function template specialization 'sol::stack::unqualified_pusher<sol::detail::as_value_tag<rn::lua::(anonymous namespace)::no_copy_type>, void>::push_fx<sol::stack::stack_detail::undefined_metatable &, const rn::lua::(anonymous namespace)::no_copy_type &>' requested here
                        return push_fx(L, fx, std::forward<Args>(args)...);
                               ^
../../extern/sol2/include/sol/stack_push.hpp:137:12: note: in instantiation of function template specialization 'sol::stack::unqualified_pusher<sol::detail::as_value_tag<rn::lua::(anonymous namespace)::no_copy_type>, void>::push_keyed<const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> &, const rn::lua::(anonymous namespace)::no_copy_type &>' requested here
                                return push_keyed(L, usertype_traits<T>::metatable(), std::forward<Arg>(arg), std::forward<Args>(args)...);
                                       ^
../../extern/sol2/include/sol/stack_core.hpp:919:14: note: in instantiation of function template specialization 'sol::stack::unqualified_pusher<sol::detail::as_value_tag<rn::lua::(anonymous namespace)::no_copy_type>, void>::push<const rn::lua::(anonymous namespace)::no_copy_type &>' requested here
                                return p.push(L, std::forward<Arg>(arg), std::forward<Args>(args)...);
                                         ^
../../extern/sol2/include/sol/stack_push.hpp:324:19: note: in instantiation of function template specialization 'sol::stack::push<sol::detail::as_value_tag<rn::lua::(anonymous namespace)::no_copy_type>, const rn::lua::(anonymous namespace)::no_copy_type &, void>' requested here
                                return stack::push<detail::as_value_tag<T>>(L, std::forward<Args>(args)...);
                                              ^
../../extern/sol2/include/sol/stack_core.hpp:919:14: note: (skipping 29 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
                                return p.push(L, std::forward<Arg>(arg), std::forward<Args>(args)...);
                                         ^
../../extern/sol2/include/sol/table_core.hpp:630:4: note: in instantiation of function template specialization 'sol::basic_table_core<true, sol::basic_reference<false>>::set<std::tuple<char const (&)[4]>, sol::function_arguments<sol::function_sig<>, rn::lua::(anonymous namespace)::my_callable>>' requested here
                        set(std::forward<Key>(key), as_function_reference(std::forward<Fx>(fx), std::forward<Args>(args)...));
                        ^
../../extern/sol2/include/sol/table_core.hpp:603:4: note: in instantiation of function template specialization 'sol::basic_table_core<true, sol::basic_reference<false>>::set_fx<rn::lua::(anonymous namespace)::my_callable, std::tuple<char const (&)[4]>, sol::meta::enable_t::_>' requested here
                        set_fx(types<>(), std::forward<Key>(key), std::forward<Args>(args)...);
                        ^
../../extern/sol2/include/sol/table_proxy.hpp:100:8: note: in instantiation of function template specialization 'sol::basic_table_core<true, sol::basic_reference<false>>::set_function<std::tuple<char const (&)[4]>, rn::lua::(anonymous namespace)::my_callable>' requested here
                        tbl.set_function(std::move(key), std::forward<Args>(args)...);
                            ^
../../extern/sol2/include/sol/table_proxy.hpp:119:29: note: in instantiation of function template specialization 'sol::table_proxy<sol::basic_table_core<true, sol::basic_reference<false>> &, std::tuple<char const (&)[4]>>::set_function<rn::lua::(anonymous namespace)::my_callable>' requested here
                                return std::move(*this).set_function(std::forward<T>(other));
                                                        ^
../../src/lua.cpp:89:16: note: in instantiation of function template specialization 'sol::table_proxy<sol::basic_table_core<true, sol::basic_reference<false>> &, std::tuple<char const (&)[4]>>::operator=<rn::lua::(anonymous namespace)::my_callable>' requested here
  st["AAA"] = my_callable{};
            ^
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_construct.h:94:5: note: candidate template ignored: substitution failure [with _Tp = rn::lua::(anonymous namespace)::no_copy_type, _Args = <const rn::lua::(anonymous namespace)::no_copy_type &>]: call to deleted constructor of 'rn::lua::(anonymous namespace)::no_copy_type'
    construct_at(_Tp* __location, _Args&&... __args)
    ^
1 error generated.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

Still working on this.

P.S.: Unicode stuff is coming. We had some wins in the C Committee - https://soasis.org/posts/planted-seeds-unicode-c-c++-2021/