decimad / luabind-deboostified

Create Lua bindings for your C++ code easily - my improvements
http://www.vrac.iastate.edu/vancegroup/docs/luabind/
Other
71 stars 26 forks source link

gcc Error: wrong number of template arguments (1, should be 3) #27

Closed 0xBADEAFFE closed 7 years ago

0xBADEAFFE commented 7 years ago
out_value_policy.hpp:199:33: error: wrong number of template arguments (1, should be 3)
    storage_.template construct<T>();
out_value_policy.hpp:220:33: error: wrong number of template arguments (1, should be 3)
    storage_.template construct<T>();
decimad commented 7 years ago

Hello, can you please provide a testcase or some sample code for me to look at?

neomantra commented 7 years ago

I'm getting this on Ubuntu 16.04 with gcc 5.4.0, latest master:

cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LUABIND=ON .
make
[ 79%] Building CXX object test/CMakeFiles/test_policies.dir/test_policies.cpp.o
In file included from /home/pc/evan/projects/luabind-deboostified/test/test_policies.cpp:26:0:
/home/pc/evan/projects/luabind-deboostified/luabind/out_value_policy.hpp: In member function ‘T& luabind::detail::pure_out_value_converter<Size, Policies>::to_cpp(lua_State*, luabind::detail::by_reference<T>, int)’:
/home/pc/evan/projects/luabind-deboostified/luabind/out_value_policy.hpp:200:34: error: wrong number of template arguments (1, should be 3)
     storage_.template construct<T>();
                                  ^
In file included from /home/pc/evan/projects/luabind-deboostified/luabind/class.hpp:83:0,
                 from /home/pc/evan/projects/luabind-deboostified/luabind/luabind.hpp:28,
                 from /home/pc/evan/projects/luabind-deboostified/test/test_policies.cpp:25:
/home/pc/evan/projects/luabind-deboostified/luabind/detail/constructor.hpp:51:10: note: provided for ‘template<class T, class Pointer, class Signature> struct luabind::detail::construct’
   struct construct :
          ^
In file included from /home/pc/evan/projects/luabind-deboostified/test/test_policies.cpp:26:0:
/home/pc/evan/projects/luabind-deboostified/luabind/out_value_policy.hpp: In member function ‘T* luabind::detail::pure_out_value_converter<Size, Policies>::to_cpp(lua_State*, luabind::detail::by_pointer<T>, int)’:
/home/pc/evan/projects/luabind-deboostified/luabind/out_value_policy.hpp:221:34: error: wrong number of template arguments (1, should be 3)
     storage_.template construct<T>();
                                  ^
In file included from /home/pc/evan/projects/luabind-deboostified/luabind/class.hpp:83:0,
                 from /home/pc/evan/projects/luabind-deboostified/luabind/luabind.hpp:28,
                 from /home/pc/evan/projects/luabind-deboostified/test/test_policies.cpp:25:
/home/pc/evan/projects/luabind-deboostified/luabind/detail/constructor.hpp:51:10: note: provided for ‘template<class T, class Pointer, class Signature> struct luabind::detail::construct’
   struct construct :
          ^
test/CMakeFiles/test_policies.dir/build.make:62: recipe for target 'test/CMakeFiles/test_policies.dir/test_policies.cpp.o' failed
make[2]: *** [test/CMakeFiles/test_policies.dir/test_policies.cpp.o] Error 1
CMakeFiles/Makefile2:2458: recipe for target 'test/CMakeFiles/test_policies.dir/all' failed
make[1]: *** [test/CMakeFiles/test_policies.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
neomantra commented 7 years ago

The Dockerfile below reproduces it on current master. Save it as Dockerfile.ubuntu and build it like so:

cd luabind-deboostified
docker build -f Dockerfile.ubuntu .
# Dockerfile.ubuntu
FROM ubuntu:16.04

RUN DEBIAN_FRONTEND=noninteractive apt-get update -y \
    && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        ca-certificates \
        cmake \ 
        g++ \
        gcc \
        git \
        lua5.1-dev \
        make

RUN cd /tmp \
    && git clone https://github.com/decimad/luabind-deboostified.git

VOLUME  /tmp/luabind-deboostified

RUN cd /tmp/luabind-deboostified \
    && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DLUABIND_BUILD_SHARED=ON . \
    && make
decimad commented 7 years ago

Hello, thank you for the feedback, I will see what I can do shortly.

neomantra commented 7 years ago

I did further exploration last night.... using ubuntu:16.10 and gcc-6 elicits the same compiler error. But, compiling on ubuntu:16.10 and clang works (with a minor fix I had to do which I'll make a PR for later today). I also tried C++14 standard with the same results.

I don't get why gcc is trying to use luabind::detail::construct instead of out_value_detail::temporary_storage_size<Size>::construct

neomantra commented 7 years ago

So as I was saying... if I rename out_value_detail::temporary_storage_size<Size>::construct to construct2 and invoke that in lines 200 and 221, then it compiles fine.

I don't think there is a proper test for this (because commenting out the line entirely still passes the test), but it is compiling.

decimad commented 7 years ago

Man, I don't understand this problem. It smells like a compiler bug really?

decimad commented 7 years ago

Oh and out_value_converter is missing the dependant template keywords as well...

decimad commented 7 years ago

I commited a preliminary fix as suggested on https://www.c-plusplus.net/forum/343641 that works without renaming.

All this line does is default-constructing an object in the already reserved memory. A pointer to this will be passed to the function as the "out"-tagged parameter, which will get overwritten right away. Since an "int" holds no invariants that could be broken, that copy operation cannot fail. That's why the test still passes if you comment out that line, it could potentially break for non-trivial types though.

Wohlstand commented 7 years ago

I'll try to build that at me

Wohlstand commented 7 years ago

Okay, you also forgot to apply fix at 221'th line where I did fix myself, but another issue has been found:

impicit_cast test fails

./test_implicit_cast
/home/wohlstand/_git_repos/luabind-deboostified/test/test_implicit_cast.cpp:59"TEST_CHECK failed: "false""

But okay:

// This test fails because shared_ptr-converter is broken.
    DOSTRING_EXPECTED(L,
        "a = A()\n"
        "no_convert(a)",
        ("No matching overload found, candidates:\n"
        "void no_convert(custom ["
        + std::string(typeid(std::shared_ptr<A>).name()) + "])").c_str());

I'll post this as another issue (if someone wasn't posted it yet)

decimad commented 7 years ago

Arrrr, I need to catch some sleep... Btw.: This problem is/was actually a bug in gcc and clang.

decimad commented 7 years ago

Okay, I think I can consider this fixed now, right?