Created attachment 53113 [details] output from -freport-bug ICE in complex constexpr/consteval context. I think this code is invalid. Debian testing gcc-12.1. - [ 83%] Building CXX object tests/CMakeFiles/expressions.dir/expressions.cpp.o /home/ldalessa/open/ttl/tests/expressions.cpp: In instantiation of ‘constexpr bool contraction(ttl::utils::type_args<I>) [with T = int]’: /home/ldalessa/open/ttl/tests/expressions.cpp:589:24: required from ‘constexpr bool tests(ttl::utils::type_args<I>) [with T = int]’ /home/ldalessa/open/ttl/tests/expressions.cpp:600:19: required from here /home/ldalessa/open/ttl/tests/expressions.cpp:149:13: internal compiler error: in extract_call_expr, at cp/call.cc:7114 149 | T dot = a(~i) * a(i); | ^~ 0x65a180 extract_call_expr(tree_node*) ../../src/gcc/cp/call.cc:7114 0x80b0cb tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../src/gcc/cp/pt.cc:20971 0x819ea1 tsubst_copy_and_build_call_args ../../src/gcc/cp/pt.cc:19937 0x80ae60 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../src/gcc/cp/pt.cc:20687 0x80a6a7 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../src/gcc/cp/pt.cc:20322 0x81b618 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:19491 0x822f79 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:16770 0x822f79 tsubst_init ../../src/gcc/cp/pt.cc:16774 0x81dc83 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:18643 0x81cb62 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:18462 0x81cb62 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:18476 0x81c158 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:18462 0x81c158 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:18833 0x81ab7c tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../src/gcc/cp/pt.cc:26412 0x81ab7c instantiate_body ../../src/gcc/cp/pt.cc:26412 0x81b439 instantiate_decl(tree_node*, bool, bool) ../../src/gcc/cp/pt.cc:26704 0x6d4962 cxx_eval_call_expression ../../src/gcc/cp/constexpr.cc:2664 0x6d6f68 cxx_eval_constant_expression ../../src/gcc/cp/constexpr.cc:6720 0x6d9011 cxx_eval_constant_expression ../../src/gcc/cp/constexpr.cc:6828 0x6d6ebe cxx_eval_constant_expression ../../src/gcc/cp/constexpr.cc:7044
Somewhat reduced testcase: template <wchar_t> struct A {}; template <wchar_t> struct B {}; template <wchar_t a> static consteval auto operator~(A<a>) -> B<a> { return {}; } A<'i'> i; template <class> auto test() -> bool { auto ii = ~i; // ICE HERE return true; } int main() { bool i = test<int>(); } https://godbolt.org/z/rEf4neexc
Thanks for the reduction, confirmed.
The ICE started with r277733 commit f968ef9b8df2bc2287e5e7e87299e5a2a44e8c94 Author: Jakub Jelinek <jakub@redhat.com> Date: Sat Nov 2 00:28:20 2019 +0100 PR c++/88335 - Implement P1073R3: Immediate functions
(In reply to Marek Polacek from comment #3) > The ICE started with r277733 > > commit f968ef9b8df2bc2287e5e7e87299e5a2a44e8c94 > Author: Jakub Jelinek <jakub@redhat.com> > Date: Sat Nov 2 00:28:20 2019 +0100 > > PR c++/88335 - Implement P1073R3: Immediate functions @Marek: Please add to CC author of a revision you bisected to.
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:f70c18524221dcefa6cd26cee7b55503181bd912 commit r13-1688-gf70c18524221dcefa6cd26cee7b55503181bd912 Author: Patrick Palka <ppalka@redhat.com> Date: Wed Jul 13 14:02:08 2022 -0400 c++: non-dependent call to consteval operator [PR105912] Here we're crashing when substituting a non-dependent call to a consteval operator, whose CALL_EXPR_OPERATOR_SYNTAX flag we try to propagate to the result, but the result isn't a CALL_EXPR since the selected function is consteval. This patch fixes this by checking the result of extract_call_expr accordingly. (Note that we can't check DECL_IMMEDIATE_FUNCTION_P here because we don't know which function was selected by overload resolution from here.) PR c++/105912 gcc/cp/ChangeLog: * pt.cc (tsubst_copy_and_build) <case CALL_EXPR>: Guard against NULL_TREE extract_call_expr result. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/consteval31.C: New test.
The releases/gcc-12 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:a074ae297d5dbd69e03c6c30f9cb7720685fdb62 commit r12-8606-ga074ae297d5dbd69e03c6c30f9cb7720685fdb62 Author: Patrick Palka <ppalka@redhat.com> Date: Thu Jul 21 12:59:44 2022 -0400 c++: non-dependent call to consteval operator [PR105912] Here we're crashing when substituting a non-dependent call to a consteval operator, whose CALL_EXPR_OPERATOR_SYNTAX flag we try to propagate to the result, but the result isn't a CALL_EXPR since the selected function is consteval. This patch fixes this by checking the result of extract_call_expr accordingly. (Note that we can't check DECL_IMMEDIATE_FUNCTION_P here because we don't know which function was selected by overload resolution from here.) PR c++/105912 gcc/cp/ChangeLog: * call.cc (extract_call_expr): Return a NULL_TREE on failure instead of asserting. * pt.cc (tsubst_copy_and_build) <case CALL_EXPR>: Guard against NULL_TREE extract_call_expr result. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/consteval31.C: New test. (cherry picked from commit f70c18524221dcefa6cd26cee7b55503181bd912)
Fixed for GCC 12.2/13