public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102191] New: Can't return prvalue with potentially-throwing destructor during constant evaluation
@ 2021-09-03 14:57 johelegp at gmail dot com
2022-01-06 2:08 ` [Bug c++/102191] [C++20] " jason at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: johelegp at gmail dot com @ 2021-09-03 14:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102191
Bug ID: 102191
Summary: Can't return prvalue with potentially-throwing
destructor during constant evaluation
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: johelegp at gmail dot com
CC: johelegp at gmail dot com
Target Milestone: ---
See https://godbolt.org/z/8evPWv7cb.
```C++
struct X {
struct A {
constexpr ~A() noexcept(false) { }
};
constexpr A operator()(auto...) { return {}; }
};
void f() { []() consteval { X{}(); }(); }
```
```
<source>: In function 'void f()':
<source>:9:37: in 'constexpr' expansion of '<lambda closure
object>f()::<lambda()>().f()::<lambda()>()'
<source>:9:37: in 'constexpr' expansion of 'X::operator()(auto:1 ...) [with
auto:1 = {}]()'
<source>:9:37: error: modification of '<anonymous>' is not a constant
expression
9 | void f() { []() consteval { X{}(); }(); }
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~
Compiler returned: 1
```
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/102191] [C++20] Can't return prvalue with potentially-throwing destructor during constant evaluation
2021-09-03 14:57 [Bug c++/102191] New: Can't return prvalue with potentially-throwing destructor during constant evaluation johelegp at gmail dot com
@ 2022-01-06 2:08 ` jason at gcc dot gnu.org
2022-01-07 0:26 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2022-01-06 2:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102191
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
Last reconfirmed| |2022-01-06
Summary|Can't return prvalue with |[C++20] Can't return
|potentially-throwing |prvalue with
|destructor during constant |potentially-throwing
|evaluation |destructor during constant
| |evaluation
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/102191] [C++20] Can't return prvalue with potentially-throwing destructor during constant evaluation
2021-09-03 14:57 [Bug c++/102191] New: Can't return prvalue with potentially-throwing destructor during constant evaluation johelegp at gmail dot com
2022-01-06 2:08 ` [Bug c++/102191] [C++20] " jason at gcc dot gnu.org
@ 2022-01-07 0:26 ` cvs-commit at gcc dot gnu.org
2022-02-01 22:51 ` jason at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-07 0:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102191
--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:b10e031458d541f794dfaa08ba606487603a4bb6
commit r12-6333-gb10e031458d541f794dfaa08ba606487603a4bb6
Author: Jason Merrill <jason@redhat.com>
Date: Wed Jan 5 17:01:12 2022 -0500
c++: destroy retval on throwing cleanup in try [PR33799]
My earlier attempt to fix this bug didn't handle the case where both the
return and the throwing cleanup are within a try-block that catches and
discards the exception. Fixed by adding the retval cleanup to any
try-blocks as well as the function body. PR102191 pointed out that we also
weren't handling templates properly, so I moved the call out of the parser.
PR c++/33799
PR c++/102191
gcc/cp/ChangeLog:
* except.c (maybe_splice_retval_cleanup): Check
current_binding_level.
* semantics.c (do_poplevel): Call it here.
* parser.c (cp_parser_compound_statement): Not here.
gcc/testsuite/ChangeLog:
* g++.dg/eh/return1.C: Add temporary in try block case.
* g++.dg/cpp2a/constexpr-dtor11.C: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/102191] [C++20] Can't return prvalue with potentially-throwing destructor during constant evaluation
2021-09-03 14:57 [Bug c++/102191] New: Can't return prvalue with potentially-throwing destructor during constant evaluation johelegp at gmail dot com
2022-01-06 2:08 ` [Bug c++/102191] [C++20] " jason at gcc dot gnu.org
2022-01-07 0:26 ` cvs-commit at gcc dot gnu.org
@ 2022-02-01 22:51 ` jason at gcc dot gnu.org
2023-11-02 20:01 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2022-02-01 22:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102191
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.0
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 12.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/102191] [C++20] Can't return prvalue with potentially-throwing destructor during constant evaluation
2021-09-03 14:57 [Bug c++/102191] New: Can't return prvalue with potentially-throwing destructor during constant evaluation johelegp at gmail dot com
` (2 preceding siblings ...)
2022-02-01 22:51 ` jason at gcc dot gnu.org
@ 2023-11-02 20:01 ` cvs-commit at gcc dot gnu.org
2023-11-17 0:21 ` cvs-commit at gcc dot gnu.org
2023-11-17 0:21 ` cvs-commit at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-02 20:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102191
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:ae07265381d934ee97fb1ce8915731158c91babc
commit r14-5086-gae07265381d934ee97fb1ce8915731158c91babc
Author: Jason Merrill <jason@redhat.com>
Date: Mon Oct 30 17:44:54 2023 -0400
c++: retval dtor on rethrow [PR112301]
In r12-6333 for PR33799, I fixed the example in [except.ctor]/2. In that
testcase, the exception is caught and the function returns again,
successfully.
In this testcase, however, the exception is rethrown, and hits two separate
cleanups: one in the try block and the other in the function body. So we
destroy twice an object that was only constructed once.
Fortunately, the fix for the normal case is easy: we just need to clear the
"return value constructed by return" flag when we do it the first time.
This gets more complicated with the named return value optimization, since
we don't want to destroy the return value while the NRV variable is still
in
scope.
PR c++/112301
PR c++/102191
PR c++/33799
gcc/cp/ChangeLog:
* except.cc (maybe_splice_retval_cleanup): Clear
current_retval_sentinel when destroying retval.
* semantics.cc (nrv_data): Add in_nrv_cleanup.
(finalize_nrv): Set it.
(finalize_nrv_r): Fix handling of throwing cleanups.
gcc/testsuite/ChangeLog:
* g++.dg/eh/return1.C: Add more cases.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/102191] [C++20] Can't return prvalue with potentially-throwing destructor during constant evaluation
2021-09-03 14:57 [Bug c++/102191] New: Can't return prvalue with potentially-throwing destructor during constant evaluation johelegp at gmail dot com
` (3 preceding siblings ...)
2023-11-02 20:01 ` cvs-commit at gcc dot gnu.org
@ 2023-11-17 0:21 ` cvs-commit at gcc dot gnu.org
2023-11-17 0:21 ` cvs-commit at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-17 0:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102191
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:7fae9873a74c7a5a62044bb6a4cde8e3ac1a5e5d
commit r12-9990-g7fae9873a74c7a5a62044bb6a4cde8e3ac1a5e5d
Author: Jason Merrill <jason@redhat.com>
Date: Mon Oct 30 17:44:54 2023 -0400
c++: retval dtor on rethrow [PR112301]
In r12-6333 for PR33799, I fixed the example in [except.ctor]/2. In that
testcase, the exception is caught and the function returns again,
successfully.
In this testcase, however, the exception is rethrown, and hits two separate
cleanups: one in the try block and the other in the function body. So we
destroy twice an object that was only constructed once.
Fortunately, the fix for the normal case is easy: we just need to clear the
"return value constructed by return" flag when we do it the first time.
This gets more complicated with the named return value optimization, since
we don't want to destroy the return value while the NRV variable is still
in
scope.
PR c++/112301
PR c++/102191
PR c++/33799
gcc/cp/ChangeLog:
* except.cc (maybe_splice_retval_cleanup): Clear
current_retval_sentinel when destroying retval.
* semantics.cc (nrv_data): Add in_nrv_cleanup.
(finalize_nrv): Set it.
(finalize_nrv_r): Fix handling of throwing cleanups.
gcc/testsuite/ChangeLog:
* g++.dg/eh/return1.C: Add more cases.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/102191] [C++20] Can't return prvalue with potentially-throwing destructor during constant evaluation
2021-09-03 14:57 [Bug c++/102191] New: Can't return prvalue with potentially-throwing destructor during constant evaluation johelegp at gmail dot com
` (4 preceding siblings ...)
2023-11-17 0:21 ` cvs-commit at gcc dot gnu.org
@ 2023-11-17 0:21 ` cvs-commit at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-17 0:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102191
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:d237e7b291ff52095d600e6489a54b4ba8aaf608
commit r13-8079-gd237e7b291ff52095d600e6489a54b4ba8aaf608
Author: Jason Merrill <jason@redhat.com>
Date: Mon Oct 30 17:44:54 2023 -0400
c++: retval dtor on rethrow [PR112301]
In r12-6333 for PR33799, I fixed the example in [except.ctor]/2. In that
testcase, the exception is caught and the function returns again,
successfully.
In this testcase, however, the exception is rethrown, and hits two separate
cleanups: one in the try block and the other in the function body. So we
destroy twice an object that was only constructed once.
Fortunately, the fix for the normal case is easy: we just need to clear the
"return value constructed by return" flag when we do it the first time.
This gets more complicated with the named return value optimization, since
we don't want to destroy the return value while the NRV variable is still
in
scope.
PR c++/112301
PR c++/102191
PR c++/33799
gcc/cp/ChangeLog:
* except.cc (maybe_splice_retval_cleanup): Clear
current_retval_sentinel when destroying retval.
* semantics.cc (nrv_data): Add in_nrv_cleanup.
(finalize_nrv): Set it.
(finalize_nrv_r): Fix handling of throwing cleanups.
gcc/testsuite/ChangeLog:
* g++.dg/eh/return1.C: Add more cases.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-11-17 0:21 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03 14:57 [Bug c++/102191] New: Can't return prvalue with potentially-throwing destructor during constant evaluation johelegp at gmail dot com
2022-01-06 2:08 ` [Bug c++/102191] [C++20] " jason at gcc dot gnu.org
2022-01-07 0:26 ` cvs-commit at gcc dot gnu.org
2022-02-01 22:51 ` jason at gcc dot gnu.org
2023-11-02 20:01 ` cvs-commit at gcc dot gnu.org
2023-11-17 0:21 ` cvs-commit at gcc dot gnu.org
2023-11-17 0:21 ` cvs-commit 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).