From 23e59c8633a8ba22d6913bce2b4cf57af8bd8b00 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Tue, 13 Dec 2016 19:11:36 -0500 Subject: [PATCH] Work around gcc 7 ICE Current g++ 7 snapshot fails to compile pybind under -std=c++17 with: ``` $ make [ 3%] Building CXX object tests/CMakeFiles/pybind11_tests.dir/pybind11_tests.cpp.o In file included from /home/jagerman/src/pybind11/tests/pybind11_tests.h:2:0, from /home/jagerman/src/pybind11/tests/pybind11_tests.cpp:10: /home/jagerman/src/pybind11/include/pybind11/pybind11.h: In instantiation of 'pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...):: [with Func = pybind11::cpp_function::cpp_function(Return (Class::*)(Arg ...), const Extra& ...) [with Return = int; Class = ConstructorStats; Arg = {}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]::; Return = int; Args = {ConstructorStats*}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]': /home/jagerman/src/pybind11/include/pybind11/pybind11.h:120:22: required from 'struct pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...) [with Func = pybind11::cpp_function::cpp_function(Return (Class::*)(Arg ...), const Extra& ...) [with Return = int; Class = ConstructorStats; Arg = {}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]::; Return = int; Args = {ConstructorStats*}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]::' /home/jagerman/src/pybind11/include/pybind11/pybind11.h:120:19: required from 'void pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...) [with Func = pybind11::cpp_function::cpp_function(Return (Class::*)(Arg ...), const Extra& ...) [with Return = int; Class = ConstructorStats; Arg = {}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]::; Return = int; Args = {ConstructorStats*}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]' /home/jagerman/src/pybind11/include/pybind11/pybind11.h:62:9: required from 'pybind11::cpp_function::cpp_function(Return (Class::*)(Arg ...), const Extra& ...) [with Return = int; Class = ConstructorStats; Arg = {}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]' /home/jagerman/src/pybind11/include/pybind11/pybind11.h:984:22: required from 'pybind11::class_& pybind11::class_::def(const char*, Func&&, const Extra& ...) [with Func = int (ConstructorStats::*)(); Extra = {}; type_ = ConstructorStats; options = {}]' /home/jagerman/src/pybind11/tests/pybind11_tests.cpp:24:47: required from here /home/jagerman/src/pybind11/include/pybind11/pybind11.h:147:9: sorry, unimplemented: unexpected AST of kind cleanup_stmt }; ^ /home/jagerman/src/pybind11/include/pybind11/pybind11.h:147:9: internal compiler error: in potential_constant_expression_1, at cp/constexpr.c:5593 0x84c52a potential_constant_expression_1 ../../src/gcc/cp/constexpr.c:5593 0x84c3c0 potential_constant_expression_1 ../../src/gcc/cp/constexpr.c:5154 0x645511 finish_function(int) ../../src/gcc/cp/decl.c:15527 0x66e80b instantiate_decl(tree_node*, int, bool) ../../src/gcc/cp/pt.c:22558 0x6b61e2 instantiate_class_template_1 ../../src/gcc/cp/pt.c:10444 0x6b61e2 instantiate_class_template(tree_node*) ../../src/gcc/cp/pt.c:10514 0x75a676 complete_type(tree_node*) ../../src/gcc/cp/typeck.c:133 0x67d5a4 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../src/gcc/cp/pt.c:17516 0x67ca19 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../src/gcc/cp/pt.c:16655 0x672cce tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.c:16140 0x6713dc tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.c:15408 0x671915 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.c:15394 0x671fc0 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.c:15618 0x66e97f tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.c:15379 0x66e97f instantiate_decl(tree_node*, int, bool) ../../src/gcc/cp/pt.c:22536 0x6ba0cb instantiate_pending_templates(int) ../../src/gcc/cp/pt.c:22653 0x6fd7f8 c_parse_final_cleanups() ../../src/gcc/cp/decl2.c:4512 ``` which looks a lot like https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77545. The error seems to be that it gets confused about the `std::tuple<...> value` in argument_loader: it is apparently not being initialized properly. Adding a default constructor with an explicit default-initialization of `value` works around the problem. --- include/pybind11/cast.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 535516b37..ed61c10f8 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1220,6 +1220,8 @@ class argument_loader { using indices = make_index_sequence; public: + argument_loader() : value() {} // Helps gcc-7 properly initialize value + static constexpr auto has_kwargs = std::is_same>::value; static constexpr auto has_args = has_kwargs || std::is_same>::value;