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

            Bug ID: 65295
           Summary: [C++1y] constexpr function causes ICE if it returns a
                    local variable bigger than 16 bytes
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kariya_mitsuru at hotmail dot com

Created attachment 34934
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34934&action=edit
g++ -v

The sample code below causes ICE.

========================== sample code ==========================
struct arr {
    constexpr arr() : elem() {}
    char elem[17];
};

constexpr arr f()
{
    arr result;
    return result;
}

constexpr arr a{f()};

int main(){}
========================== sample code ==========================

========================== ICE output ==========================
prog.cc:12:19:   in constexpr expansion of 'f()'
prog.cc:12:20: internal compiler error: in cxx_eval_constant_expression, at
cp/constexpr.c:2959
constexpr arr a{f()};
                   ^
0x6fac0e cxx_eval_constant_expression
    /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:2959
0x6f86ed cxx_eval_constant_expression
    /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3117
0x6f84e2 cxx_eval_conditional_expression
    /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:1678
0x6f84e2 cxx_eval_constant_expression
    /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3316
0x6fb451 cxx_eval_statement_list
    /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:2866
0x6f85ab cxx_eval_constant_expression
    /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3388
0x6f8ecc cxx_eval_constant_expression
    /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3394
0x6fde37 cxx_eval_call_expression
    /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:1392
0x6f8eab cxx_eval_constant_expression
    /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3021
0x6fb610 cxx_eval_outermost_constant_expr
    /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3529
0x639247 store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
    /home/heads/gcc/gcc-source/gcc/cp/typeck2.c:833
0x60bde5 check_initializer
    /home/heads/gcc/gcc-source/gcc/cp/decl.c:6002
0x60cf3c cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int)
    /home/heads/gcc/gcc-source/gcc/cp/decl.c:6638
0x68108e cp_parser_init_declarator
    /home/heads/gcc/gcc-source/gcc/cp/parser.c:17282
0x6826ec cp_parser_simple_declaration
    /home/heads/gcc/gcc-source/gcc/cp/parser.c:11592
0x6829e3 cp_parser_block_declaration
    /home/heads/gcc/gcc-source/gcc/cp/parser.c:11466
0x687db9 cp_parser_declaration
    /home/heads/gcc/gcc-source/gcc/cp/parser.c:11363
0x68803a cp_parser_declaration_seq_opt
    /home/heads/gcc/gcc-source/gcc/cp/parser.c:11249
0x68866f cp_parser_translation_unit
    /home/heads/gcc/gcc-source/gcc/cp/parser.c:4100
0x68866f c_parse_file()
    /home/heads/gcc/gcc-source/gcc/cp/parser.c:33173
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.
========================== ICE output ==========================

cf. http://melpon.org/wandbox/permlink/GaYaqMrDUdWiU65i


It does not cause ICE if
  (1) sizeof(arr) is smaller than or equal to 16.
     cf. http://melpon.org/wandbox/permlink/lNwMp9fSmYG9vOzc
  or
  (2) it is compiled with -fno-elide-constructors.
     cf. http://melpon.org/wandbox/permlink/HK7UlzKRPmLTqmz7

Reply via email to