Code Monkey home page Code Monkey logo

Comments (3)

wzhengsen avatar wzhengsen commented on June 2, 2024

Just now, found out that compiling with clang also has this error.

from sol2.

Rochet2 avatar Rochet2 commented on June 2, 2024

This is the error (godbolt)

In file included from <source>:4:
In file included from /opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/sol.hpp:54:
In file included from /opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/usertype.hpp:27:
In file included from /opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/usertype_core.hpp:37:
In file included from /opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/usertype_container_launch.hpp:28:
/opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/usertype_container.hpp:541:12: error: non-const lvalue reference to type 'span<...>' cannot bind to a temporary of type 'span<...>'
  541 |                                 return stack::unqualified_get<T>(L, 1);
      |                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/usertype_container.hpp:1212:17: note: in instantiation of member function 'sol::container_detail::usertype_container_default<std::span<std::basic_string<char>>>::get_src' requested here
 1212 |                                 auto& src = get_src(L);
      |                                             ^
/opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/usertype_container.hpp:1353:12: note: in instantiation of function template specialization 'sol::container_detail::usertype_container_default<std::span<std::basic_string<char>>>::pairs_associative<false>' requested here
 1353 |                                 return pairs_associative<false>(is_assoc(), L);
      |                                        ^
/opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/usertype_container_launch.hpp:125:16: note: in instantiation of member function 'sol::container_detail::usertype_container_default<std::span<std::basic_string<char>>>::pairs' requested here
  125 |                                 return uc::pairs(L);
      |                                            ^
/opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/usertype_container_launch.hpp:133:12: note: in instantiation of member function 'sol::container_detail::u_c_launch<std::span<std::basic_string<char>>>::real_pairs_traits' requested here
  133 |                                 return real_pairs_traits(container_detail::has_traits_pairs<uc>(), L);
      |                                        ^
/opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/usertype_container_launch.hpp:286:74: note: in instantiation of member function 'sol::container_detail::u_c_launch<std::span<std::basic_string<char>>>::real_pairs_call' requested here
  286 |                                 return detail::typed_static_trampoline<decltype(&real_pairs_call), (&real_pairs_call)>(L);
      |                                                                                                      ^
/opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/usertype_container_launch.hpp:335:46: note: (skipping 8 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
  335 |                                                 { "__pairs", &meta_usertype_container::pairs_call },
      |                                                                                        ^
/opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/stack_core.hpp:948:19: note: in instantiation of function template specialization 'sol::stack::push<sol::detail::as_reference_tag, std::span<std::basic_string<char>> &, void>' requested here
  948 |                                 return stack::push<Tr>(L, std::forward<Arg>(arg), std::forward<Args>(args)...);
      |                                               ^
/opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/stack_core.hpp:955:25: note: in instantiation of function template specialization 'sol::stack::stack_detail::push_reference<std::span<std::basic_string<char>> &, std::span<std::basic_string<char>> &>' requested here
  955 |                         return stack_detail::push_reference<T>(L, std::forward<T>(t), std::forward<Args>(args)...);
      |                                              ^
/opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/stack_core.hpp:982:20: note: in instantiation of function template specialization 'sol::stack::push_reference<std::span<std::basic_string<char>> &>' requested here
  982 |                         int pushcount = push_reference(L, std::forward<T>(t));
      |                                         ^
/opt/compiler-explorer/libs/sol2/v3.2.1/include/sol/unsafe_function.hpp:169:27: note: in instantiation of function template specialization 'sol::stack::multi_push_reference<std::span<std::basic_string<char>> &>' requested here
  169 |                         int pushcount = stack::multi_push_reference(lua_state(), std::forward<Args>(args)...);
      |                                                ^
<source>:21:4: note: in instantiation of function template specialization 'sol::basic_function<sol::basic_reference<false>, false>::operator()<std::span<std::basic_string<char>> &>' requested here
   21 |         f1(sp);// compile error
      |           ^
3 warnings and 1 error generated.

Looks like the issue is here

return stack::unqualified_get<T>(L_, 1);

The function returns auto&, but when #define SOL_SAFE_USERTYPE 0 is set, stack::unqualified_get<T>(L_, 1); is returned. Changing it to stack::unqualified_get<T&>(L_, 1); probably fixes the issue, as it is similar to the code when the setting is on.

from sol2.

wzhengsen avatar wzhengsen commented on June 2, 2024

@Rochet2
You inspired me to try your program.
But it still doesn't pass compilation and I used instead:

return *stack::unqualified_get<T*>(L_, 1);

It works.

from sol2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.