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

            Bug ID: 91791
           Summary: ICE when throwing exception in a ternary expression
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tonvandenheuvel at gmail dot com
  Target Milestone: ---

The following code results in an ICE using GCC 9.2.0:


#include <string>

std::string f(const std::string& s)
{
  return !s.empty() ? s : throw "Invalid";
}

int main(int argc, char** argv)
{
  return f(std::string(argc, 'x'));
}


$ g++ test.cpp
test.cpp: In function ‘std::string f(const string&)’:
test.cpp:5:33: internal compiler error: in ocp_convert, at cp/cvt.c:766
    5 |   return !s.empty() ? s : throw "Invalid";
      |                                 ^~~~~~~~~
0x5f5ef5 ocp_convert(tree_node*, tree_node*, int, int, int)
        ../.././gcc/cp/cvt.c:766
0x787612 check_return_expr(tree_node*, bool*)
        ../.././gcc/cp/typeck.c:9800
0x7567bf finish_return_stmt(tree_node*)
        ../.././gcc/cp/semantics.c:894
0x6fbb95 cp_parser_jump_statement
        ../.././gcc/cp/parser.c:12919
0x6fbb95 cp_parser_statement
        ../.././gcc/cp/parser.c:11191
0x6fc208 cp_parser_statement_seq_opt
        ../.././gcc/cp/parser.c:11657
0x6fc2c0 cp_parser_compound_statement
        ../.././gcc/cp/parser.c:11611
0x712850 cp_parser_function_body
        ../.././gcc/cp/parser.c:22660
0x712850 cp_parser_ctor_initializer_opt_and_function_body
        ../.././gcc/cp/parser.c:22711
0x713031 cp_parser_function_definition_after_declarator
        ../.././gcc/cp/parser.c:27812
0x713cfb cp_parser_function_definition_from_specifiers_and_declarator
        ../.././gcc/cp/parser.c:27728
0x713cfb cp_parser_init_declarator
        ../.././gcc/cp/parser.c:20297
0x6f8e6e cp_parser_simple_declaration
        ../.././gcc/cp/parser.c:13541
0x719020 cp_parser_declaration
        ../.././gcc/cp/parser.c:13238
0x719749 cp_parser_translation_unit
        ../.././gcc/cp/parser.c:4701
0x719749 c_parse_file()
        ../.././gcc/cp/parser.c:41191
0x7d41db c_common_parse_file()
        ../.././gcc/c-family/c-opts.c:1160


This might be related to bug 91740? I am not sure though, hence the report.

Reply via email to