public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100588] New: Destroying delete shouldn't be called if constructor throws
@ 2021-05-13 15:08 richardpku at gmail dot com
2021-05-13 15:26 ` [Bug c++/100588] " redi at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: richardpku at gmail dot com @ 2021-05-13 15:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100588
Bug ID: 100588
Summary: Destroying delete shouldn't be called if constructor
throws
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: richardpku at gmail dot com
Target Milestone: ---
Consider this program:
#include <cstdio>
#include <new>
class A {
public:
A() { throw 42; }
~A() { puts("A::~A"); }
void operator delete(void* p) {
puts("regular delete invoked");
::operator delete(p);
}
void operator delete(A* p, std::destroying_delete_t) {
puts("destroying delete invoked");
p->~A();
::operator delete(p);
}
};
int main() {
try {
new A;
} catch (int) {
}
}
Output compiled with GCC:
destroying delete invoked
A::~A
Output compiled with Clang:
regular delete invoked
I believe clang has the correct behavior.
A destroying delete function is expected to invoke the destructor explicitly.
As a result, the current GCC implementation would indirectly invoke the
destructor on an instance that wasn't successfully constructed, which obviously
isn't the intended behavior.
It is even worse if class A has a base class, in which case the destructor of
the base class is called twice if an exception is thrown in A's constructor.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/100588] Destroying delete shouldn't be called if constructor throws
2021-05-13 15:08 [Bug c++/100588] New: Destroying delete shouldn't be called if constructor throws richardpku at gmail dot com
@ 2021-05-13 15:26 ` redi at gcc dot gnu.org
2022-01-06 21:46 ` jason at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2021-05-13 15:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100588
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Keywords| |wrong-code
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-05-13
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/100588] Destroying delete shouldn't be called if constructor throws
2021-05-13 15:08 [Bug c++/100588] New: Destroying delete shouldn't be called if constructor throws richardpku at gmail dot com
2021-05-13 15:26 ` [Bug c++/100588] " redi at gcc dot gnu.org
@ 2022-01-06 21:46 ` jason at gcc dot gnu.org
2022-01-08 2:03 ` cvs-commit at gcc dot gnu.org
2022-02-02 23:41 ` jason at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2022-01-06 21:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100588
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
CC| |jason at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/100588] Destroying delete shouldn't be called if constructor throws
2021-05-13 15:08 [Bug c++/100588] New: Destroying delete shouldn't be called if constructor throws richardpku at gmail dot com
2021-05-13 15:26 ` [Bug c++/100588] " redi at gcc dot gnu.org
2022-01-06 21:46 ` jason at gcc dot gnu.org
@ 2022-01-08 2:03 ` cvs-commit at gcc dot gnu.org
2022-02-02 23:41 ` jason at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-08 2:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100588
--- 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:75047f795111150fd10a8f86f5c72deab10cde77
commit r12-6380-g75047f795111150fd10a8f86f5c72deab10cde77
Author: Jason Merrill <jason@redhat.com>
Date: Thu Jan 6 13:26:21 2022 -0500
c++: destroying delete, throw in new-expr [PR100588]
The standard says that a destroying operator delete is preferred, but that
only applies to the delete-expression, not the cleanup if a new-expression
initialization throws. As a result of this patch, several of the
destroying
delete tests don't get EH cleanups, but I'm turning off the warning in
cases
where the initialization can't throw anyway.
It's unclear what should happen if the class does not declare a
non-deleting
operator delete; a proposal in CWG was to call the global delete, which
makes sense to me if the class doesn't declare its own operator new. If it
does, we warn and don't call any deallocation function if initialization
throws.
PR c++/100588
gcc/cp/ChangeLog:
* call.c (build_op_delete_call): Ignore destroying delete
if alloc_fn.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/destroying-delete5.C: Expect warning.
* g++.dg/cpp2a/destroying-delete6.C: New test.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/100588] Destroying delete shouldn't be called if constructor throws
2021-05-13 15:08 [Bug c++/100588] New: Destroying delete shouldn't be called if constructor throws richardpku at gmail dot com
` (2 preceding siblings ...)
2022-01-08 2:03 ` cvs-commit at gcc dot gnu.org
@ 2022-02-02 23:41 ` jason at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2022-02-02 23:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100588
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |12.0
--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 12 so far.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-02-02 23:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-13 15:08 [Bug c++/100588] New: Destroying delete shouldn't be called if constructor throws richardpku at gmail dot com
2021-05-13 15:26 ` [Bug c++/100588] " redi at gcc dot gnu.org
2022-01-06 21:46 ` jason at gcc dot gnu.org
2022-01-08 2:03 ` cvs-commit at gcc dot gnu.org
2022-02-02 23:41 ` jason 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).