public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113853] New: implicit move in throw in trailing return type
@ 2024-02-09 18:18 mpolacek at gcc dot gnu.org
2024-02-09 18:18 ` [Bug c++/113853] " mpolacek at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-09 18:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113853
Bug ID: 113853
Summary: implicit move in throw in trailing return type
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mpolacek at gcc dot gnu.org
Target Milestone: ---
Found while working on bug 98388. This should compile fine in all dialects:
```
// { dg-do compile { target c++11 } }
struct moveonly {
moveonly() = default;
moveonly(moveonly&&) = default;
};
template<class T>
constexpr auto is_throwable(T t) -> decltype(throw t, true) {
return true;
}
template<class T>
constexpr bool is_throwable(...) { return false; }
constexpr bool b = is_throwable<moveonly>(moveonly{});
#if __cplusplus >= 202002L
static_assert (b, "move from the function parameter");
#else
static_assert (!b, "no move from the function parameter");
#endif
```
but it doesn't; see
<https://gcc.gnu.org/pipermail/gcc-patches/2024-February/645275.html>.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113853] implicit move in throw in trailing return type
2024-02-09 18:18 [Bug c++/113853] New: implicit move in throw in trailing return type mpolacek at gcc dot gnu.org
@ 2024-02-09 18:18 ` mpolacek at gcc dot gnu.org
2024-02-10 15:00 ` arthur.j.odwyer at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-09 18:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113853
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Last reconfirmed| |2024-02-09
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
Keywords| |rejects-valid
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113853] implicit move in throw in trailing return type
2024-02-09 18:18 [Bug c++/113853] New: implicit move in throw in trailing return type mpolacek at gcc dot gnu.org
2024-02-09 18:18 ` [Bug c++/113853] " mpolacek at gcc dot gnu.org
@ 2024-02-10 15:00 ` arthur.j.odwyer at gmail dot com
2024-02-16 17:09 ` cvs-commit at gcc dot gnu.org
2024-02-16 17:13 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2024-02-10 15:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113853
Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |arthur.j.odwyer at gmail dot com
--- Comment #1 from Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> ---
(Sorry, not sure where's the best place to put this comment. Maybe nowhere. ;))
You probably know this already, but just in case anyone's not on the same page
yet:
https://eel.is/c++draft/except.throw#5
> When the thrown object is a class object, the constructor selected for the copy-initialization *as well as the constructor selected for a copy-initialization considering the thrown object as an lvalue* shall be non-deleted and accessible, even if the copy/move operation is elided.
That paragraph is lurking in the background every time we talk about GCC's
handling of move-only exception objects. However, my impression is that the
paragraph is ignorable from the vendor's point of view:
- Even on paper, this "shall" is talking only about the runtime behavior "when
an exception _is_ thrown," so it doesn't change anything about the
well-formedness of _unevaluated_ throw-expressions.
- GCC+Clang _probably could_ conformingly decide that it should be ill-formed
to `throw x` when `x` is move-only; but that would break a lot of users, so
pragmatically they can't do that. GCC+Clang need a consistent theory of what it
means to throw a move-only type, and the theory can't possibly be "it's
ill-formed" (because that would break users), so the theory must agree with
Marek's test case: `throw t` ought to be well-formed in C++20-and-later (by
wording introduced to C++20 in P1155 a.k.a. P1825).
IOW, this bug and test case are *not* invalidated by [except.throw]/5. That's
all. :)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113853] implicit move in throw in trailing return type
2024-02-09 18:18 [Bug c++/113853] New: implicit move in throw in trailing return type mpolacek at gcc dot gnu.org
2024-02-09 18:18 ` [Bug c++/113853] " mpolacek at gcc dot gnu.org
2024-02-10 15:00 ` arthur.j.odwyer at gmail dot com
@ 2024-02-16 17:09 ` cvs-commit at gcc dot gnu.org
2024-02-16 17:13 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ 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=113853
--- Comment #2 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] 5+ messages in thread
* [Bug c++/113853] implicit move in throw in trailing return type
2024-02-09 18:18 [Bug c++/113853] New: implicit move in throw in trailing return type mpolacek at gcc dot gnu.org
` (2 preceding siblings ...)
2024-02-16 17:09 ` cvs-commit at gcc dot gnu.org
@ 2024-02-16 17:13 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-16 17:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113853
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in GCC 14.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-16 17:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-09 18:18 [Bug c++/113853] New: implicit move in throw in trailing return type mpolacek at gcc dot gnu.org
2024-02-09 18:18 ` [Bug c++/113853] " mpolacek at gcc dot gnu.org
2024-02-10 15:00 ` arthur.j.odwyer at gmail dot com
2024-02-16 17:09 ` cvs-commit at gcc dot gnu.org
2024-02-16 17:13 ` mpolacek at gcc dot gnu.org
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).