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

            Bug ID: 68087
           Summary: ICE with constexpr in array with negative index
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roger.ferrer at bsc dot es
  Target Milestone: ---

Hi,

GCC 6.0.0 20151025 and 5.2 crash with an ICE with the following code:

-- ice.cc
constexpr char c[] = "hello";
constexpr const char *p = c;

void f()
{
    static_assert(*(p-1) == 'h', "");
}
-- end of ice.cc

$ g++ --version
g++ (GCC) 6.0.0 20151025 (experimental)
$ g++ -std=c++11 -c ice.cc

ice.cc: In function ‘void f()’:
ice.cc:6:37: internal compiler error: in tree_to_shwi, at tree.c:7304
     static_assert(*(p-1) == 'h', "");
                                     ^
0xf2fec2 tree_to_shwi(tree_node const*)
        ../../gcc-git/gcc/tree.c:7304
0x7fc084 cxx_eval_array_reference
        ../../gcc-git/gcc/cp/constexpr.c:1785
0x7fc084 cxx_eval_constant_expression
        ../../gcc-git/gcc/cp/constexpr.c:3485
0x7fb18c cxx_eval_indirect_ref
        ../../gcc-git/gcc/cp/constexpr.c:2588
0x7fb18c cxx_eval_constant_expression
        ../../gcc-git/gcc/cp/constexpr.c:3340
0x7fe63e cxx_eval_binary_expression
        ../../gcc-git/gcc/cp/constexpr.c:1601
0x7fa994 cxx_eval_constant_expression
        ../../gcc-git/gcc/cp/constexpr.c:3462
0x7fff0b cxx_eval_outermost_constant_expr
        ../../gcc-git/gcc/cp/constexpr.c:3746
0x801980 maybe_constant_value(tree_node*, tree_node*)
        ../../gcc-git/gcc/cp/constexpr.c:3859
0x772f15 finish_static_assert(tree_node*, tree_node*, unsigned int, bool)
        ../../gcc-git/gcc/cp/semantics.c:8291
0x6f47a2 cp_parser_static_assert
        ../../gcc-git/gcc/cp/parser.c:12662
0x70b099 cp_parser_block_declaration
        ../../gcc-git/gcc/cp/parser.c:11880
0x70bed1 cp_parser_declaration_statement
        ../../gcc-git/gcc/cp/parser.c:11496
0x70804a cp_parser_statement
        ../../gcc-git/gcc/cp/parser.c:10162
0x708971 cp_parser_statement_seq_opt
        ../../gcc-git/gcc/cp/parser.c:10440
0x708a73 cp_parser_compound_statement
        ../../gcc-git/gcc/cp/parser.c:10394
0x708c00 cp_parser_function_body
        ../../gcc-git/gcc/cp/parser.c:20216
0x708c00 cp_parser_ctor_initializer_opt_and_function_body
        ../../gcc-git/gcc/cp/parser.c:20252
0x709929 cp_parser_function_definition_after_declarator
        ../../gcc-git/gcc/cp/parser.c:24856
0x70a82b cp_parser_function_definition_from_specifiers_and_declarator
        ../../gcc-git/gcc/cp/parser.c:24768
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 5.1 and earlier emit a diagnostic instead:

$ g++-5.1 -std=c++11 -c ice.cc
ice.cc: In function ‘void f()’:
ice.cc:6:5: error: non-constant condition for static assertion
     static_assert(*(p-1) == 'h', "");
     ^
ice.cc:6:5: error: array subscript out of bound

Kind regards,

Reply via email to