https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113789
Bug ID: 113789 Summary: ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: arthur.j.odwyer at gmail dot com Target Milestone: --- P2266 "Simpler Implicit Move", adopted for C++23, intends that a move-eligible `x` should be treated as an xvalue in the context of `throw x`. This means that `throw x` should be ill-formed (SFINAE-friendly) when `x` isn't move-constructible. (This might be complicated by the GCC+Clang extension that permits move-only types to be thrown even though the paper Standard technically prohibits that.) That is, the test program in this blog post is expected to pass after P2266: https://quuxplusone.github.io/blog/2021/03/18/sfinae-on-throw-x/#here-is-a-program-that-uses-sfin Clang passes; GCC fails; MSVC and EDG don't seem to implement P2266 `throw` yet. But the real problem for GCC is that if you then use `throw x` inside the function body after using `decltype(throw x)` in the function's return type, the compiler ICEs! // https://godbolt.org/z/YG16hE7zT struct AutoPtr { AutoPtr() = default; AutoPtr(AutoPtr&) {} }; template<class T> auto f(T p, int) -> decltype(throw p, 1) { throw p; } template<class T> int f(T p, long) { return 2; } int main() { return f(AutoPtr(), 42); } The expected behavior (and Clang's behavior) is to call `f(T, long)`. GCC 12 generates a call to `f(T, int)`. GCC 13 crashes with this output (including that leading single-quote): ' internal compiler error: error reporting routines re-entered. 0x2648345 diagnostic_context::report_diagnostic(diagnostic_info*) ???:0 0x26494c5 error_at(unsigned int, char const*, ...) ???:0 0xa7d834 build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, tree_node**, int) ???:0 0xa7eb5b build_special_member_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, int) ???:0 0xb685e4 build_throw(unsigned int, tree_node*) ???:0 0xc95e47 tsubst(tree_node*, tree_node*, int, tree_node*) ???:0 0x267035c pp_format(pretty_printer*, text_info*, urlifier const*) ???:0 0x2673055 pp_verbatim(pretty_printer*, char const*, ...) ???:0 0x26481ca diagnostic_context::report_diagnostic(diagnostic_info*) ???:0 0x26494c5 error_at(unsigned int, char const*, ...) ???:0 0xa7d834 build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, tree_node**, int) ???:0 0xa7eb5b build_special_member_call(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, tree_node*, int, int) ???:0 0xb685e4 build_throw(unsigned int, tree_node*) ???:0 0xc8b5c3 instantiate_decl(tree_node*, bool, bool) ???:0 0xcb56cb instantiate_pending_templates(int) ???:0 0xb54d39 c_parse_final_cleanups() ???:0 0xda8358 c_common_parse_file() ???:0