[Bug c++/61362] g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2 does not compile lambda with template

daniel.kruegler at googlemail dot com gcc-bugzilla@gcc.gnu.org
Fri May 30 15:14:00 GMT 2014


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

--- Comment #2 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
Reduced example (removing library dependencies) using compiler flags

 -Wall -Wextra -std=c++11 -pedantic 

for gcc HEAD 4.10.0 20140529 (experimental)

//---------------------
struct function {
  template<class F>
  function(F){}

  void operator()(...) {}
};

struct Node {
  unsigned length;
};

template<typename N>
class C {
public:
  unsigned longest = 0;
  function f = [this](N node) {
    if(node->length > this->longest) this->longest = node->length;
  };
};

int main() {
  Node n;
  n.length = 5;
  C<Node*> c;
  c.f(&n);
}
//---------------------

results in

"prog.cc: In instantiation of 'C<N>::<lambda(N)> [with N = Node*]':
prog.cc:16:17: required from 'struct C<Node*>::<lambda(struct Node*)>'
prog.cc:24:12: required from here prog.cc:16:29: internal compiler error:
Segmentation fault function f = [this](N node) { ^ 0x96976f crash_signal
/home/heads/gcc/gcc-source/gcc/toplev.c:337 0x56ddb5
instantiate_decl(tree_node*, int, bool)
/home/heads/gcc/gcc-source/gcc/cp/pt.c:19932 0x5802b1
instantiate_class_template_1 /home/heads/gcc/gcc-source/gcc/cp/pt.c:9367
0x5802b1 instantiate_class_template(tree_node*)
/home/heads/gcc/gcc-source/gcc/cp/pt.c:9435 0x5d726d complete_type(tree_node*)
/home/heads/gcc/gcc-source/gcc/cp/typeck.c:134 0x567644
tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
/home/heads/gcc/gcc-source/gcc/cp/pt.c:15327 0x5ec715 get_nsdmi(tree_node*,
bool) /home/heads/gcc/gcc-source/gcc/cp/init.c:543 0x5f4bf4 walk_field_subobs
/home/heads/gcc/gcc-source/gcc/cp/method.c:1098 0x5f53bc
synthesized_method_walk /home/heads/gcc/gcc-source/gcc/cp/method.c:1424
0x5f64b5 get_defaulted_eh_spec(tree_node*)
/home/heads/gcc/gcc-source/gcc/cp/method.c:1455 0x581707
maybe_instantiate_noexcept(tree_node*)
/home/heads/gcc/gcc-source/gcc/cp/pt.c:19563 0x599ae7 mark_used(tree_node*,
int) /home/heads/gcc/gcc-source/gcc/cp/decl2.c:4823 0x537459 build_over_call
/home/heads/gcc/gcc-source/gcc/cp/call.c:7325 0x53de3a build_new_method_call_1
/home/heads/gcc/gcc-source/gcc/cp/call.c:8037 0x53de3a
build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
/home/heads/gcc/gcc-source/gcc/cp/call.c:8107 0x53e6e6
build_special_member_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, int)
/home/heads/gcc/gcc-source/gcc/cp/call.c:7651 0x5ef036 expand_default_init
/home/heads/gcc/gcc-source/gcc/cp/init.c:1713 0x5ef036 expand_aggr_init_1
/home/heads/gcc/gcc-source/gcc/cp/init.c:1814 0x5f096e
build_aggr_init(tree_node*, tree_node*, int, int)
/home/heads/gcc/gcc-source/gcc/cp/init.c:1566 0x549a2d
build_aggr_init_full_exprs /home/heads/gcc/gcc-source/gcc/cp/decl.c:5642 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."


More information about the Gcc-bugs mailing list