public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53868] New: Temporary for indirect binding is not destroyed when destructor from initializer temp throws
@ 2012-07-06 3:21 hstong at ca dot ibm.com
2012-07-06 8:17 ` [Bug c++/53868] " redi at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: hstong at ca dot ibm.com @ 2012-07-06 3:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53868
Bug #: 53868
Summary: Temporary for indirect binding is not destroyed when
destructor from initializer temp throws
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: hstong@ca.ibm.com
Host: powerpc64-unknown-linux-gnu
Target: powerpc64-unknown-linux-gnu
The temporary created for indirect binding should be completely constructed
(and from the output _it is_) before the destructors for temporaries in the
initializer are called.
In the following case, the destructor for a temporary in the initializer throws
an int. During stack unwinding, it seems the temporary bound to the reference
is missed.
### Self-contained source:> cat tempbindIndirect_inittempDtorThrows.cpp
extern "C" int printf(const char *, ...);
extern "C" void abort();
struct SubobjectInA {
SubobjectInA();
~SubobjectInA();
};
struct A : SubobjectInA {
A() = delete;
A(const A &) = delete;
A(A &&) { }
A(int);
~A();
};
#define TRACE_FUNC( ... ) \
{ printf("%s\n", __PRETTY_FUNCTION__); __VA_ARGS__ }
struct Q {
Q() : q(0) TRACE_FUNC()
~Q();
int q;
};
int main() {
try { const A &a = Q().q; }
catch (...) { return 0; }
abort();
}
SubobjectInA::SubobjectInA() TRACE_FUNC()
SubobjectInA::~SubobjectInA() TRACE_FUNC()
A::A(int) TRACE_FUNC()
A::~A() TRACE_FUNC()
Q::~Q() TRACE_FUNC( throw 0; )
### Compiler invocation:
g++-4.7.0 -std='c++11' tempbindIndirect_inittempDtorThrows.cpp -o test
### Compiler output:
(return code 0)
### Output from resulting executable:> ./test ; echo rc=$?
Q::Q()
SubobjectInA::SubobjectInA()
A::A(int)
Q::~Q()
rc=0
### Expected output:
Q::Q()
SubobjectInA::SubobjectInA()
A::A(int)
Q::~Q()
A::~A()
SubobjectInA::~SubobjectInA()
rc=0
### gcc -v output:> g++-4.7.0 -v
Using built-in specs.
COLLECT_GCC=g++-4.7.0
COLLECT_LTO_WRAPPER=/data/gcc/libexec/gcc/powerpc64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: powerpc64-unknown-linux-gnu
Configured with: ../gcc-4.7.0/configure --prefix=/data/gcc
--program-suffix=-4.7.0 --disable-libssp --disable-libgcj
--enable-version-specific-runtime-libs --with-cpu=default32 --enable-secureplt
--with-long-double-128 --enable-shared --enable-__cxa_atexit
--enable-threads=posix --enable-languages=c,c++,fortran --with-mpfr=/usr/local/
--with-mpc=/usr/local/ --with-gmp=/usr/local/
Thread model: posix
gcc version 4.7.0 (GCC)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53868] Temporary for indirect binding is not destroyed when destructor from initializer temp throws
2012-07-06 3:21 [Bug c++/53868] New: Temporary for indirect binding is not destroyed when destructor from initializer temp throws hstong at ca dot ibm.com
@ 2012-07-06 8:17 ` redi at gcc dot gnu.org
2021-08-27 9:36 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2012-07-06 8:17 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53868
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-07-06 08:17:16 UTC ---
(It doesn't matter for 4.7 but you need noexcept(false) on Q::~Q to use the
testcase on trunk)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53868] Temporary for indirect binding is not destroyed when destructor from initializer temp throws
2012-07-06 3:21 [Bug c++/53868] New: Temporary for indirect binding is not destroyed when destructor from initializer temp throws hstong at ca dot ibm.com
2012-07-06 8:17 ` [Bug c++/53868] " redi at gcc dot gnu.org
@ 2021-08-27 9:36 ` pinskia at gcc dot gnu.org
2022-01-06 21:47 ` jason at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-27 9:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53868
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target|powerpc64-unknown-linux-gnu |
Host|powerpc64-unknown-linux-gnu |
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=66139,
| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=52320
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang and GCC both produce the same result while ICC produces the bug reporter
expected result.
This is also most likely related to PR 66139 and PR 52320.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53868] Temporary for indirect binding is not destroyed when destructor from initializer temp throws
2012-07-06 3:21 [Bug c++/53868] New: Temporary for indirect binding is not destroyed when destructor from initializer temp throws hstong at ca dot ibm.com
2012-07-06 8:17 ` [Bug c++/53868] " redi at gcc dot gnu.org
2021-08-27 9:36 ` pinskia at gcc dot gnu.org
@ 2022-01-06 21:47 ` jason at gcc dot gnu.org
2022-01-07 0:26 ` cvs-commit at gcc dot gnu.org
2022-01-28 4:34 ` jason at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2022-01-06 21:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53868
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2022-01-06
Ever confirmed|0 |1
CC| |jason at gcc dot gnu.org
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53868] Temporary for indirect binding is not destroyed when destructor from initializer temp throws
2012-07-06 3:21 [Bug c++/53868] New: Temporary for indirect binding is not destroyed when destructor from initializer temp throws hstong at ca dot ibm.com
` (2 preceding siblings ...)
2022-01-06 21:47 ` jason at gcc dot gnu.org
@ 2022-01-07 0:26 ` cvs-commit at gcc dot gnu.org
2022-01-28 4:34 ` jason at gcc dot gnu.org
4 siblings, 0 replies; 6+ 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=53868
--- Comment #3 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:4c6afbbd48f0c40ddf949bc403d9bd5f5e14204f
commit r12-6332-g4c6afbbd48f0c40ddf949bc403d9bd5f5e14204f
Author: Jason Merrill <jason@redhat.com>
Date: Wed Jan 5 11:18:25 2022 -0500
c++: clean up ref-extended temp on throwing dtor [PR53868]
We have wrap_temporary_cleanups to handle the EH region nesting problems
between cleanups for complete variables and cleanups for temporaries used
in
their construction, but we weren't calling it for temporaries extended from
binding to a reference.
We still don't want this for array cleanups (since my PR94041 fix), so I
move that exception from initialize_local_var to wrap_temporary_cleanups.
PR c++/53868
gcc/cp/ChangeLog:
* decl.c (cp_finish_decl): Use wrap_temporary_cleanups for
cleanups from set_up_extended_ref_temp.
(wrap_temporary_cleanups): Ignore array cleanups.
(initialize_local_var): Don't check for array here.
* cp-tree.h (BIND_EXPR_VEC_DTOR): New.
* init.c (build_vec_delete_1): Set it.
gcc/testsuite/ChangeLog:
* g++.dg/eh/ref-temp1.C: New test.
* g++.dg/eh/ref-temp2.C: New test.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/53868] Temporary for indirect binding is not destroyed when destructor from initializer temp throws
2012-07-06 3:21 [Bug c++/53868] New: Temporary for indirect binding is not destroyed when destructor from initializer temp throws hstong at ca dot ibm.com
` (3 preceding siblings ...)
2022-01-07 0:26 ` cvs-commit at gcc dot gnu.org
@ 2022-01-28 4:34 ` jason at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2022-01-28 4:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53868
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
Target Milestone|--- |12.0
--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 12.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-01-28 4:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-06 3:21 [Bug c++/53868] New: Temporary for indirect binding is not destroyed when destructor from initializer temp throws hstong at ca dot ibm.com
2012-07-06 8:17 ` [Bug c++/53868] " redi at gcc dot gnu.org
2021-08-27 9:36 ` pinskia at gcc dot gnu.org
2022-01-06 21:47 ` jason at gcc dot gnu.org
2022-01-07 0:26 ` cvs-commit at gcc dot gnu.org
2022-01-28 4:34 ` 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).