https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123495
Bug ID: 123495
Summary: ICE: unexpected expression ‘(int (*)())(0)’ of kind
cast_expr in cxx_eval_constant_expression within
template during nodiscard check
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: 522024330006 at smail dot nju.edu.cn
Target Milestone: ---
Go back to gcc 14.1(assertions)
To reproduce: https://godbolt.org/z/9ccon14Wd
GCC crashes with an ICE when a function call, performed via a cast to a
function pointer returning a non-void type, is used within a template. The
crash occurs during the nodiscard warning check in convert_to_void
Program:
```
#include <vector>
template <typename T>
class C {
public:
void bar() {
((int(*)())(0))();
}
};
```
Traceback:
```
internal compiler error: unexpected expression '(int (*)())(0)' of kind
cast_expr
23 | ((int(*)())(0))(); // Function call where the callee is not a
function type
| ~^~~~~~~~~~~~~~
0x5da1dc8 internal_error(char const*, ...)
/workspace/install/gcc/src/gcc/gcc/diagnostic-global-context.cc:517
0xf8f75e cxx_eval_constant_expression
/workspace/install/gcc/src/gcc/gcc/cp/constexpr.cc:8965
0xf92b4d cxx_eval_outermost_constant_expr
/workspace/install/gcc/src/gcc/gcc/cp/constexpr.cc:9238
0xf95ec5 maybe_constant_init_1
/workspace/install/gcc/src/gcc/gcc/cp/constexpr.cc:9770
0xf95fb1 maybe_constant_init(tree_node*, tree_node*, bool)
/workspace/install/gcc/src/gcc/gcc/cp/constexpr.cc:9788
0x10345ea cp_get_fndecl_from_callee(tree_node*, bool)
/workspace/install/gcc/src/gcc/gcc/cp/cvt.cc:1038
0x1034c9f maybe_warn_nodiscard
/workspace/install/gcc/src/gcc/gcc/cp/cvt.cc:1091
0x1036328 convert_to_void(tree_node*, impl_conv_void, int)
/workspace/install/gcc/src/gcc/gcc/cp/cvt.cc:1280
0x15bc0bd finish_expr_stmt(tree_node*)
/workspace/install/gcc/src/gcc/gcc/cp/semantics.cc:1177
0x138ba21 cp_parser_expression_statement
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:13663
0x138a175 cp_parser_statement
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:13342
0x138c529 cp_parser_statement_seq_opt
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:13861
0x138bd1e cp_parser_compound_statement
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:13708
0x13c0ef3 cp_parser_function_body
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:26712
0x13c14d6 cp_parser_ctor_initializer_opt_and_function_body
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:26763
0x13de0cd cp_parser_function_definition_after_declarator
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:33711
0x13e3b7f cp_parser_late_parsing_for_member
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:34593
0x13c74f9 cp_parser_class_specifier
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:27940
0x13a7a22 cp_parser_type_specifier
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:20669
0x139be79 cp_parser_decl_specifier_seq
/workspace/install/gcc/src/gcc/gcc/cp/parser.cc:17255
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
```