public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113789] New: ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter
@ 2024-02-06 17:51 arthur.j.odwyer at gmail dot com
  2024-02-06 17:59 ` [Bug c++/113789] " pinskia at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2024-02-06 17:51 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-02-16 17:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-06 17:51 [Bug c++/113789] New: ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter arthur.j.odwyer at gmail dot com
2024-02-06 17:59 ` [Bug c++/113789] " pinskia at gcc dot gnu.org
2024-02-06 18:16 ` mpolacek at gcc dot gnu.org
2024-02-06 18:16 ` [Bug c++/113789] [13/14 Regression] " mpolacek at gcc dot gnu.org
2024-02-06 20:32 ` mpolacek at gcc dot gnu.org
2024-02-06 22:32 ` mpolacek at gcc dot gnu.org
2024-02-06 22:32 ` mpolacek at gcc dot gnu.org
2024-02-07  4:35 ` arthur.j.odwyer at gmail dot com
2024-02-10 15:26 ` mpolacek at gcc dot gnu.org
2024-02-16 17:09 ` cvs-commit at gcc dot gnu.org
2024-02-16 17:14 ` [Bug c++/113789] [13 " mpolacek at gcc dot gnu.org
2024-02-16 17:53 ` arthur.j.odwyer at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).