* [Bug c++/105265] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
@ 2022-04-13 14:15 ` jack.cui2 at foxmail dot com
2022-04-13 14:23 ` jack.cui2 at foxmail dot com
` (13 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: jack.cui2 at foxmail dot com @ 2022-04-13 14:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
--- Comment #1 from jack <jack.cui2 at foxmail dot com> ---
#include <iostream>
using namespace std;
class Block
{
public:
Block(int n) : data{new char[n]}, size{n}
{
cout << "Block ctor\n";
}
~Block()
{
cout << "Block dtor\n";
delete[] data;
}
private:
char* data;
int size;
};
struct Cargo
{
Block const& block;
};
int main()
{
{
Cargo* c = new Cargo{{4000}};
cout << "main\n";
delete c;
}
return 0;
}
Compile and run:
g++ -Wall -Wextra -fno-strict-aliasing -fwrapv -g -std=c++17
Output:
Block ctor
main
---------------------------
Issue: Block not destructed.
however, below forms are fine
{
Cargo{{4000}};
cout << "main";
}
{
Cargo* c = new Cargo{Block{4000}};
cout << "main";
delete c;
}
They all output:
Block ctor
Block dtor
main
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
2022-04-13 14:15 ` [Bug c++/105265] " jack.cui2 at foxmail dot com
@ 2022-04-13 14:23 ` jack.cui2 at foxmail dot com
2022-04-13 14:48 ` [Bug c++/105265] [9/10/11/12 Regression] " redi at gcc dot gnu.org
` (12 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: jack.cui2 at foxmail dot com @ 2022-04-13 14:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
--- Comment #2 from jack <jack.cui2 at foxmail dot com> ---
Additional info: g++8.4 and clang++ 3.8 have no such issue
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] [9/10/11/12 Regression] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
2022-04-13 14:15 ` [Bug c++/105265] " jack.cui2 at foxmail dot com
2022-04-13 14:23 ` jack.cui2 at foxmail dot com
@ 2022-04-13 14:48 ` redi at gcc dot gnu.org
2022-04-13 15:09 ` ppalka at gcc dot gnu.org
` (11 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2022-04-13 14:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Known to fail| |10.1.0, 10.3.0, 11.1.0,
| |11.2.0, 12.0, 9.3.0
Status|UNCONFIRMED |NEW
Keywords| |wrong-code
Known to work| |8.5.0, 9.2.0
Last reconfirmed| |2022-04-13
CC| |jason at gcc dot gnu.org
Target Milestone|--- |9.5
Summary|temporary object not |[9/10/11/12 Regression]
|destructed causing memory |temporary object not
|leaks |destructed causing memory
| |leaks
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Started with r279236
PR c++/57082 - new X{} and private destructor.
build_new_1 already passes tf_no_cleanup to build_value_init, but in this
testcase we end up calling build_value_init by way of
build_special_member_call, so we need to pass it to that function as well.
* init.c (build_new_1): Also pass tf_no_cleanup to
build_special_member_call.
Backported to gcc-9 as r279335
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] [9/10/11/12 Regression] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
` (2 preceding siblings ...)
2022-04-13 14:48 ` [Bug c++/105265] [9/10/11/12 Regression] " redi at gcc dot gnu.org
@ 2022-04-13 15:09 ` ppalka at gcc dot gnu.org
2022-04-13 15:10 ` redi at gcc dot gnu.org
` (10 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-04-13 15:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
The testcase seems to work correctly with trunk for me.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] [9/10/11/12 Regression] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
` (3 preceding siblings ...)
2022-04-13 15:09 ` ppalka at gcc dot gnu.org
@ 2022-04-13 15:10 ` redi at gcc dot gnu.org
2022-04-13 15:14 ` [Bug c++/105265] [9/10/11 " redi at gcc dot gnu.org
` (9 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2022-04-13 15:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail|12.0 |
Known to work| |12.0
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Ah yes, it was fixed by r12-1165
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] [9/10/11 Regression] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
` (4 preceding siblings ...)
2022-04-13 15:10 ` redi at gcc dot gnu.org
@ 2022-04-13 15:14 ` redi at gcc dot gnu.org
2022-04-13 15:25 ` ppalka at gcc dot gnu.org
` (8 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2022-04-13 15:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=100838
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
But not fixed on gcc-11 by the r11-8715 backport for PR100838, suggesting there
was an earlier change on trunk that affects it.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] [9/10/11 Regression] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
` (5 preceding siblings ...)
2022-04-13 15:14 ` [Bug c++/105265] [9/10/11 " redi at gcc dot gnu.org
@ 2022-04-13 15:25 ` ppalka at gcc dot gnu.org
2022-04-13 16:13 ` jason at gcc dot gnu.org
` (7 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-04-13 15:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #6)
> But not fixed on gcc-11 by the r11-8715 backport for PR100838, suggesting
> there was an earlier change on trunk that affects it.
Perhaps that's because of (from the r11-8715 commit message):
For GCC 11, limit the changes to -fno-elide-constructors
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] [9/10/11 Regression] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
` (6 preceding siblings ...)
2022-04-13 15:25 ` ppalka at gcc dot gnu.org
@ 2022-04-13 16:13 ` jason at gcc dot gnu.org
2022-04-13 16:17 ` jason at gcc dot gnu.org
` (6 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2022-04-13 16:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> ---
Probably makes sense to remove that extra condition on the 11 branch now.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] [9/10/11 Regression] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
` (7 preceding siblings ...)
2022-04-13 16:13 ` jason at gcc dot gnu.org
@ 2022-04-13 16:17 ` jason at gcc dot gnu.org
2022-04-14 0:22 ` cvs-commit at gcc dot gnu.org
` (5 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2022-04-13 16:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
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|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] [9/10/11 Regression] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
` (8 preceding siblings ...)
2022-04-13 16:17 ` jason at gcc dot gnu.org
@ 2022-04-14 0:22 ` cvs-commit at gcc dot gnu.org
2022-04-14 6:31 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-04-14 0:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
--- Comment #9 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:019d6d4149ee97d55ce9efe4e5e470d38130cdeb
commit r12-8149-g019d6d4149ee97d55ce9efe4e5e470d38130cdeb
Author: Jason Merrill <jason@redhat.com>
Date: Wed Apr 13 12:44:54 2022 -0400
c++: add test [PR105265]
This was fixed by r12-1165, but good to have a test that doesn't need
-fno-elide-constructors.
PR c++/105265
PR c++/100838
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/initlist-new6.C: New test.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] [9/10/11 Regression] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
` (9 preceding siblings ...)
2022-04-14 0:22 ` cvs-commit at gcc dot gnu.org
@ 2022-04-14 6:31 ` rguenth at gcc dot gnu.org
2022-05-12 20:14 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-14 6:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] [9/10/11 Regression] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
` (10 preceding siblings ...)
2022-04-14 6:31 ` rguenth at gcc dot gnu.org
@ 2022-05-12 20:14 ` cvs-commit at gcc dot gnu.org
2022-05-12 21:24 ` [Bug c++/105265] [9/10 " cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-12 20:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:728f97cf0431ff342beceea4f91afa1707133248
commit r11-9985-g728f97cf0431ff342beceea4f91afa1707133248
Author: Jason Merrill <jason@redhat.com>
Date: Wed Apr 13 20:18:33 2022 -0400
c++: temp cleanup in new [PR105265]
The patch for PR100838 in GCC 11 was limited to -fno-elide-constructors for
safety, but this testcase demonstrates that it's also needed without that
flag. So let's switch to the GCC 12 patch for PR100838.
PR c++/105265
PR c++/100838
gcc/cp/ChangeLog:
* call.c (build_user_type_conversion_1): Drop
flag_elide_constructors check.
(convert_like_internal): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/initlist-new6.C: New test.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] [9/10 Regression] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
` (11 preceding siblings ...)
2022-05-12 20:14 ` cvs-commit at gcc dot gnu.org
@ 2022-05-12 21:24 ` cvs-commit at gcc dot gnu.org
2022-05-13 18:24 ` [Bug c++/105265] [9 " cvs-commit at gcc dot gnu.org
2022-05-13 18:26 ` jason at gcc dot gnu.org
14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-12 21:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:67f742536cbb60d5f8b7bba2cac0a141191e29af
commit r10-10727-g67f742536cbb60d5f8b7bba2cac0a141191e29af
Author: Jason Merrill <jason@redhat.com>
Date: Mon May 31 12:36:25 2021 -0400
c++: missing dtor with -fno-elide-constructors [PR100838]
tf_no_cleanup only applies to the outermost TARGET_EXPR, and we already
clear it for nested calls in build_over_call, but in this case both
constructor calls came from convert_like, so we need to clear it in the
recursive call as well. This revealed that we were adding an extra
ck_rvalue in direct-initialization cases where it was wrong.
PR c++/100838
PR c++/105265
gcc/cp/ChangeLog:
* call.c (convert_like_internal): Clear tf_no_cleanup when
recursing.
(build_user_type_conversion_1): Only add ck_rvalue if
LOOKUP_ONLYCONVERTING.
gcc/testsuite/ChangeLog:
* g++.dg/init/no-elide2.C: New test.
* g++.dg/cpp0x/initlist-new6.C: New test.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] [9 Regression] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
` (12 preceding siblings ...)
2022-05-12 21:24 ` [Bug c++/105265] [9/10 " cvs-commit at gcc dot gnu.org
@ 2022-05-13 18:24 ` cvs-commit at gcc dot gnu.org
2022-05-13 18:26 ` jason at gcc dot gnu.org
14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-13 18:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:200d477d3cb1593dbaa7739c6270e0a7f6c564cf
commit r9-10178-g200d477d3cb1593dbaa7739c6270e0a7f6c564cf
Author: Jason Merrill <jason@redhat.com>
Date: Mon May 31 12:36:25 2021 -0400
c++: missing dtor with -fno-elide-constructors [PR100838]
tf_no_cleanup only applies to the outermost TARGET_EXPR, and we already
clear it for nested calls in build_over_call, but in this case both
constructor calls came from convert_like, so we need to clear it in the
recursive call as well. This revealed that we were adding an extra
ck_rvalue in direct-initialization cases where it was wrong.
PR c++/100838
PR c++/105265
gcc/cp/ChangeLog:
* call.c (convert_like_internal): Clear tf_no_cleanup when
recursing.
(build_user_type_conversion_1): Only add ck_rvalue if
LOOKUP_ONLYCONVERTING.
gcc/testsuite/ChangeLog:
* g++.dg/init/no-elide2.C: New test.
* g++.dg/cpp0x/initlist-new6.C: New test.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/105265] [9 Regression] temporary object not destructed causing memory leaks
2022-04-13 14:01 [Bug c++/105265] New: temporary object not destructed causing memory leaks jack.cui2 at foxmail dot com
` (13 preceding siblings ...)
2022-05-13 18:24 ` [Bug c++/105265] [9 " cvs-commit at gcc dot gnu.org
@ 2022-05-13 18:26 ` jason at gcc dot gnu.org
14 siblings, 0 replies; 16+ messages in thread
From: jason at gcc dot gnu.org @ 2022-05-13 18:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105265
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #13 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 9.5/10.4/11.4/12.
^ permalink raw reply [flat|nested] 16+ messages in thread