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
* [Bug c++/113789] ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter
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 ` pinskia at gcc dot gnu.org
2024-02-06 18:16 ` mpolacek at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-06 17:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113789
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |ice-on-valid-code
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>GCC 12 generates a call to `f(T, int)`. GCC 13 crashes with this output
THis is because the paper was not implemented before GCC 13; see the linked bug
reports for that.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113789] ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter
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
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-06 18:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113789
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-02-06
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
CC| |mpolacek at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with r13-2905
commit 772d532e0ba1e4b22c2b7d576e14b34ee929c093
Author: Marek Polacek <polacek@redhat.com>
Date: Wed Aug 31 17:37:59 2022 -0400
c++: Implement C++23 P2266R1, Simpler implicit move [PR101165]
so mine.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113789] [13/14 Regression] ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter
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 ` mpolacek at gcc dot gnu.org
2024-02-06 20:32 ` mpolacek at gcc dot gnu.org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-06 18:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113789
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|ICE on P2266/C++23 |[13/14 Regression] ICE on
|`decltype(throw x)` where x |P2266/C++23 `decltype(throw
|is move-eligible parameter |x)` where x is
| |move-eligible parameter
Target Milestone|--- |13.3
Priority|P3 |P2
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113789] [13/14 Regression] ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter
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
` (2 preceding siblings ...)
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
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-06 20:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113789
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I have a patch for the ICE (build_throw doesn't have a complain param so we
wind up with "error reporting routines re-entered").
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113789] [13/14 Regression] ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter
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
` (3 preceding siblings ...)
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
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-06 22:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113789
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Um, that's not it. Since
struct AutoPtr {
AutoPtr() = default;
AutoPtr(AutoPtr&) {}
};
template<class T> int
f (T p)
{
throw p;
}
void
g ()
{
f (AutoPtr ());
}
is rejected in C++23, we probably should have rejected the decltype(throw p, 1)
candidate and never get to the throw in the body of the function f.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113789] [13/14 Regression] ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter
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
` (4 preceding siblings ...)
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
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-06 22:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113789
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
IOW, this should be accepted in C++23 but isn't (clang++ accepts in C++23):
struct AutoPtr {
AutoPtr() = default;
AutoPtr(AutoPtr&) {}
};
template<class T> auto f(T p, int) -> decltype(throw p, 1) = delete;
template<class T> void f(T p, long);
void
g ()
{
f (AutoPtr (), 42);
}
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113789] [13/14 Regression] ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter
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
` (5 preceding siblings ...)
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
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2024-02-07 4:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113789
--- Comment #6 from Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> ---
(In reply to Marek Polacek from comment #5)
> IOW, this should be accepted in C++23 but isn't (clang++ accepts in C++23): [...]
Correct, at least that's my intended interpretation. But the unexpected ICE was
more dramatic. :)
I'd be a tiny bit surprised if fixing `decltype(throw p)` actually closes the
only pathway to that ICE; but if it does, then awesome, I have no complaints.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113789] [13/14 Regression] ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter
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
` (6 preceding siblings ...)
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
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-10 15:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113789
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The ICE was fixed by r14-8903-g3a3e0f1b46a3ad. But I'm not done here yet.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113789] [13/14 Regression] ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter
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
` (7 preceding siblings ...)
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
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-16 17:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113789
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:254ff3d0e34835b4de93d5e5763a7366dc7d989d
commit r14-9034-g254ff3d0e34835b4de93d5e5763a7366dc7d989d
Author: Marek Polacek <polacek@redhat.com>
Date: Wed Feb 14 17:53:52 2024 -0500
c++: implicit move with throw [PR113853]
Here we have
template<class T>
auto is_throwable(T t) -> decltype(throw t, true) { ... }
where we didn't properly mark 't' as IMPLICIT_RVALUE_P, which caused
the wrong overload to have been chosen. Jason figured out it's because
we don't correctly implement [expr.prim.id.unqual]#4.2, which post-P2266
says that an id-expression is move-eligible if
"the id-expression (possibly parenthesized) is the operand of
a throw-expression, and names an implicitly movable entity that belongs
to a scope that does not contain the compound-statement of the innermost
lambda-expression, try-block, or function-try-block (if any) whose
compound-statement or ctor-initializer contains the throw-expression."
I worked out that it's trying to say that given
struct X {
X();
X(const X&);
X(X&&) = delete;
};
the following should fail: the scope of the throw is an sk_try, and it's
also x's scope S, and S "does not contain the compound-statement of the
*try-block" so x is move-eligible, so we move, so we fail.
void f ()
try {
X x;
throw x; // use of deleted function
} catch (...) {
}
Whereas here:
void g (X x)
try {
throw x;
} catch (...) {
}
the throw is again in an sk_try, but x's scope is an sk_function_parms
which *does* contain the {} of the *try-block, so x is not move-eligible,
so we don't move, so we use X(const X&), and the code is fine.
The current code also doesn't seem to handle
void h (X x) {
void z (decltype(throw x, true));
}
where there's no enclosing lambda or sk_try so we should move.
I'm not doing anything about lambdas because we shouldn't reach the
code at the end of the function: the DECL_HAS_VALUE_EXPR_P check
shouldn't let us go further.
PR c++/113789
PR c++/113853
gcc/cp/ChangeLog:
* typeck.cc (treat_lvalue_as_rvalue_p): Update code to better
reflect [expr.prim.id.unqual]#4.2.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/sfinae69.C: Remove dg-bogus.
* g++.dg/cpp0x/sfinae70.C: New test.
* g++.dg/cpp0x/sfinae71.C: New test.
* g++.dg/cpp0x/sfinae72.C: New test.
* g++.dg/cpp2a/implicit-move4.C: New test.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113789] [13 Regression] ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter
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
` (8 preceding siblings ...)
2024-02-16 17:09 ` cvs-commit at gcc dot gnu.org
@ 2024-02-16 17:14 ` mpolacek at gcc dot gnu.org
2024-02-16 17:53 ` arthur.j.odwyer at gmail dot com
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-16 17:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113789
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Summary|[13/14 Regression] ICE on |[13 Regression] ICE on
|P2266/C++23 `decltype(throw |P2266/C++23 `decltype(throw
|x)` where x is |x)` where x is
|move-eligible parameter |move-eligible parameter
Resolution|--- |FIXED
--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Should be fully fixed now.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113789] [13 Regression] ICE on P2266/C++23 `decltype(throw x)` where x is move-eligible parameter
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
` (9 preceding siblings ...)
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
10 siblings, 0 replies; 12+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2024-02-16 17:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113789
--- Comment #10 from Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> ---
FWIW, I think I agree with your analysis. To reiterate what you already said
(and I think GCC already gets the following snippet correct): in
X g (X x) try {
throw x;
} catch (...) {
return x;
}
the `throw x` copies but the `return x` moves. That is, `throw x` treats `x` as
an lvalue because it could be used again later (in the function-catch-block),
but `return x` treats it as an rvalue because it can't[*] be used again later.
[* — except if you sneakily use a captured reference within a destructor, but
C++ implicit move doesn't care — has never cared — about such sneaky uses]
^ 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).