coroutines: Do not promote temporaries that will be elided.
authorIain Sandoe <iain@sandoe.co.uk>
Wed, 30 Nov 2022 17:05:56 +0000 (17:05 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Sun, 4 Dec 2022 10:39:36 +0000 (10:39 +0000)
commit58a7b1e354530d8dfe7d8fb859c8b8b5a9140f1f
tree1d5aa2a02785dc85b25480d17af01e2af6a0055b
parent8c45e67ac673bbddaaf9770a1a6944b382174938
coroutines: Do not promote temporaries that will be elided.

We usually need to 'promote' (i.e. save to the coroutine frame) any temporary
variable that is in a target expression that must persist across an await
expression.  However, if the TE is just used as a direct initializer for
another object it will be elided - and we should not promote it since that
would lead to a DTOR call for something that is never constructed.

Since we now have a mechanism to tell if TEs will be elided, use that.

Although the PRs referenced initially appear to be different issues, they all
stem from this.

Co-Authored-By: Adrian Perl <adrian.perl@web.de>
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
PR c++/100611
PR c++/101367
PR c++/101976
PR c++/99576

gcc/cp/ChangeLog:

* coroutines.cc (find_interesting_subtree): Do not promote temporaries
that are only used as direct initializers for some other object.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/pr100611.C: New test.
* g++.dg/coroutines/pr101367.C: New test.
* g++.dg/coroutines/pr101976.C: New test.
* g++.dg/coroutines/pr99576_1.C: New test.
* g++.dg/coroutines/pr99576_2.C: New test.
gcc/cp/coroutines.cc
gcc/testsuite/g++.dg/coroutines/pr100611.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr101367.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr101976.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr99576_1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr99576_2.C [new file with mode: 0644]