https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68518

            Bug ID: 68518
           Summary: ICE on invalid code using lambda in variadic template
                    in tsubst_copy, at cp/pt.c:12997
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Caspar at Kielwein dot de
  Target Milestone: ---

Created attachment 36820
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36820&action=edit
preprocessed code that triggers the ice

The following code (with invalid use of constexpr) causes an internal compiler
error.

#include <type_traits>
template<class... dummy> constexpr bool void_check(dummy...) {return 0;}

template<class source_t,class sink_t>
struct connection {
        source_t source;
        sink_t sink;

        template<class param>
        auto operator()(const param& p)
                -> typename std::enable_if<void_check(source, sink) == 0,
                decltype(sink(source(p)))>::type        {
                return sink(source(p));
        }
};

template<class source_t,class sink_t>
auto connect(const source_t& source, const sink_t& sink){
        return connection<source_t, sink_t>{source, sink};
}

auto increment = [](int i) -> int {return i+1;};
auto give_one = [](void) ->int {return 1;};
auto one_plus_one = connect(give_one, increment);


I could reproduce it with 4.8, 4.9, 5.2.1 and development snapshot:
gcc version 5.2.1 20151117 (GCC)
both locally and on https://gcc.godbolt.org/

clang rejects the code: error: non-type template argument is not a constant
expression

gcc "-std=gnu++14" -save-temps gcc_bug_check.cpp 
gcc_bug_check.cpp: In instantiation of ‘struct connection<<lambda()>,
<lambda(int)> >’:
gcc_bug_check.cpp:20:50:   required from ‘auto connect(const source_t&, const
sink_t&) [with source_t = <lambda()>; sink_t = <lambda(int)>]’
gcc_bug_check.cpp:25:48:   required from here
gcc_bug_check.cpp:12:40: internal compiler error: in tsubst_copy, at
cp/pt.c:12997
   -> typename std::enable_if<void_check(source, sink) == 0,
                                        ^
0x657131 tsubst_copy
        ../../gcc-5-20151117/gcc/cp/pt.c:12997
0x647f68 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../gcc-5-20151117/gcc/cp/pt.c:15741
0x6483e1 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../gcc-5-20151117/gcc/cp/pt.c:14791
0x648c28 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../gcc-5-20151117/gcc/cp/pt.c:14772
0x648831 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../gcc-5-20151117/gcc/cp/pt.c:15523
0x649185 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../gcc-5-20151117/gcc/cp/pt.c:15234
0x649047 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool,
bool)
        ../../gcc-5-20151117/gcc/cp/pt.c:14931
0x650562 tsubst_expr
        ../../gcc-5-20151117/gcc/cp/pt.c:14553
0x6514ec tsubst_template_arg
        ../../gcc-5-20151117/gcc/cp/pt.c:9811
0x655b99 tsubst_template_args
        ../../gcc-5-20151117/gcc/cp/pt.c:10372
0x6560c4 tsubst_aggr_type
        ../../gcc-5-20151117/gcc/cp/pt.c:10569
0x64ad69 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc-5-20151117/gcc/cp/pt.c:12543
0x65549b tsubst_function_type
        ../../gcc-5-20151117/gcc/cp/pt.c:11739
0x64b174 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc-5-20151117/gcc/cp/pt.c:12482
0x6578de tsubst_decl
        ../../gcc-5-20151117/gcc/cp/pt.c:10960
0x64b484 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc-5-20151117/gcc/cp/pt.c:11955
0x6582cf tsubst_decl
        ../../gcc-5-20151117/gcc/cp/pt.c:10807
0x64b484 tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc-5-20151117/gcc/cp/pt.c:11955
0x662db1 instantiate_class_template_1
        ../../gcc-5-20151117/gcc/cp/pt.c:9470
0x662db1 instantiate_class_template(tree_node*)
        ../../gcc-5-20151117/gcc/cp/pt.c:9792
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu

Reply via email to