[Bug c++/64227] New: Forwarding an argument of a function template to a generic lambda causes a compiler crash

ville.voutilainen at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Dec 8 16:32:00 GMT 2014


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

            Bug ID: 64227
           Summary: Forwarding an argument of a function template to a
                    generic lambda causes a compiler crash
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ville.voutilainen at gmail dot com
                CC: jason at redhat dot com

The problem occurs with forward and move, but not with a static_cast<T&&>(t).

#include <utility>

template<typename T>
auto greater_than(T&& t)
{
  return [val = std::forward<T&&>(t)] (const auto& arg) { return arg > val; };
}



template<typename Functor>
void g(Functor f)
{
  for (int i = 0; i < 100000; i++)
    f(i);
}

int main()
{
  g(greater_than(10));
}

[ville@localhost ~]$ g++ --std=c++1z -c lambda-bada-boom.cpp 
lambda-bada-boom.cpp: In function ‘auto greater_than(T&&)’:
lambda-bada-boom.cpp:6:36: internal compiler error: Segmentation fault
   return [val = std::forward<T&&>(t)] (const auto& arg) { return arg > val; };
                                    ^
0xc954af crash_signal
        ../../gcc/toplev.c:359
0xf1bb0a tree_class_check(tree_node*, tree_code_class, char const*, int, char
const*)
        ../../gcc/tree.h:2886
0xf1bb0a variably_modified_type_p(tree_node*, tree_node*)
        ../../gcc/tree.c:8809
0x7d9b79 add_capture(tree_node*, tree_node*, tree_node*, bool, bool)
        ../../gcc/cp/lambda.c:486
0x6e6f9f cp_parser_lambda_introducer
        ../../gcc/cp/parser.c:9252
0x6e6f9f cp_parser_lambda_expression
        ../../gcc/cp/parser.c:8964
0x6e6f9f cp_parser_primary_expression
        ../../gcc/cp/parser.c:4447
0x6ebe0d cp_parser_postfix_expression
        ../../gcc/cp/parser.c:6089
0x6eca19 cp_parser_unary_expression
        ../../gcc/cp/parser.c:7370
0x6ed7a7 cp_parser_binary_expression
        ../../gcc/cp/parser.c:8104
0x6edd1f cp_parser_assignment_expression
        ../../gcc/cp/parser.c:8347
0x6f036d cp_parser_expression
        ../../gcc/cp/parser.c:8501
0x6e60d2 cp_parser_jump_statement
        ../../gcc/cp/parser.c:10995
0x6e60d2 cp_parser_statement
        ../../gcc/cp/parser.c:9651
0x6e6842 cp_parser_statement_seq_opt
        ../../gcc/cp/parser.c:10039
0x6e699b cp_parser_compound_statement
        ../../gcc/cp/parser.c:9993
0x6f3e8b cp_parser_function_body
        ../../gcc/cp/parser.c:19093
0x6f3e8b cp_parser_ctor_initializer_opt_and_function_body
        ../../gcc/cp/parser.c:19129
0x6fe1ca cp_parser_function_definition_after_declarator
        ../../gcc/cp/parser.c:23369
0x700103 cp_parser_function_definition_from_specifiers_and_declarator
        ../../gcc/cp/parser.c:23281
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