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

            Bug ID: 67050
           Summary: [C++14] ICE when calling a template member function
                    from a lambda with implicit "this" capture
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ldionne.2 at gmail dot com
  Target Milestone: ---

Hi,

The following code triggers an ICE (segmentation fault) on GCC trunk:
---------------------------------------------------------------------
struct Foo {
    template <typename>
    void X() { }

    void test() {
        auto by_ref = [&](auto arg) {
            // anything that makes X<...> dependent will do
            X<decltype(arg)>();
        };
        by_ref(1);

        auto by_val = [=](auto arg) {
            X<decltype(arg)>();
        };
        by_val(1);
    }
};


int main() {
    Foo foo;
    foo.test();
}
---------------------------------------------------------------------


Formatted to fit the report, the error is:
---------------------------------------------------------------------
prog.cc: In lambda function:
prog.cc:8:29: internal compiler error: Segmentation fault
             X<decltype(arg)>();
                             ^
0xae69af crash_signal
    /home/heads/gcc/gcc-source/gcc/toplev.c:352
0x854887 size_binop_loc(unsigned int, tree_code, tree_node*, tree_node*)
    /home/heads/gcc/gcc-source/gcc/fold-const.c:1732
0x9308fd gimplify_compound_lval
    /home/heads/gcc/gcc-source/gcc/gimplify.c:2014
0x92bb93 gimplify_expr(tree_node**, gimple_statement_base**, 
                                    gimple_statement_base**, 
                                    bool (*)(tree_node*), int)
    /home/heads/gcc/gcc-source/gcc/gimplify.c:8021
0x9314bb gimplify_call_expr
    /home/heads/gcc/gcc-source/gcc/gimplify.c:2452
0x92d26d gimplify_expr(tree_node**, gimple_statement_base**, 
                                    gimple_statement_base**, 
                                    bool (*)(tree_node*), int)
    /home/heads/gcc/gcc-source/gcc/gimplify.c:8040
0x92ea06 gimplify_stmt(tree_node**, gimple_statement_base**)
    /home/heads/gcc/gcc-source/gcc/gimplify.c:5525
0x92cf5d gimplify_cleanup_point_expr
    /home/heads/gcc/gcc-source/gcc/gimplify.c:5301
0x92cf5d gimplify_expr(tree_node**, gimple_statement_base**, 
                                    gimple_statement_base**, 
                                    bool (*)(tree_node*), int)
    /home/heads/gcc/gcc-source/gcc/gimplify.c:8432
0x92ea06 gimplify_stmt(tree_node**, gimple_statement_base**)
    /home/heads/gcc/gcc-source/gcc/gimplify.c:5525
0x92f7af gimplify_bind_expr
    /home/heads/gcc/gcc-source/gcc/gimplify.c:1111
0x92d24c gimplify_expr(tree_node**, gimple_statement_base**, 
                                    gimple_statement_base**, 
                                    bool (*)(tree_node*), int)
    /home/heads/gcc/gcc-source/gcc/gimplify.c:8266
0x92ea06 gimplify_stmt(tree_node**, gimple_statement_base**)
    /home/heads/gcc/gcc-source/gcc/gimplify.c:5525
0x93491e gimplify_body(tree_node*, bool)
    /home/heads/gcc/gcc-source/gcc/gimplify.c:9203
0x934c47 gimplify_function_tree(tree_node*)
    /home/heads/gcc/gcc-source/gcc/gimplify.c:9361
0x782da7 cgraph_node::analyze()
    /home/heads/gcc/gcc-source/gcc/cgraphunit.c:636
0x785447 analyze_functions
    /home/heads/gcc/gcc-source/gcc/cgraphunit.c:1028
0x785cf0 symbol_table::finalize_compilation_unit()
    /home/heads/gcc/gcc-source/gcc/cgraphunit.c:2477
------------------------------------------------------------------------------

Live example: http://melpon.org/wandbox/permlink/eN6sRg5AacE50CrZ
Note that Clang compiles this code just fine.

Curiously enough, using any of the following lambdas will 
not trigger the ICE:

(1)
    [this](auto arg) {
        X<decltype(arg)>();
    };

(2)
    [this](auto arg) {
        this->X<decltype(arg)>();
    };

(3)
    [=](auto arg) {
        this->X<decltype(arg)>();
    };

(4)
    [&](auto arg) {
        this->X<decltype(arg)>();
    };

I will also attach a test case checking for all of the above patterns.
You might want to add this to GCC's unit tests.


Related to 53741 and 54604
Maybe a duplicate of 61636


Regards,
Louis Dionne

Reply via email to