On 7/22/24 9:43 AM, Patrick Palka wrote:
Tested on x86_64-pc-linux-gnu, does this look OK for trunk
and perhaps backports?
-- >8 --
When passing *this to the promise type ctor (or operator new) (as
per [dcl.fct.def.coroutine]/4), we add an explicit cast to lvalue
reference, but that's unnecessary since *this is already an lvalue.
And it'd mean we'd have to call convert_from_reference afterwards to
lower the reference-yielding expression into an implicit dereference,
otherwise overload resolution gets confused when computing argument
conversions. So this patch removes the unnecessary reference cast when
passing *this to the promise ctor, and removes both the cast and
implicit deref when passing *this to operator new, for consistency.
PR c++/104981
PR c++/115550
gcc/cp/ChangeLog:
* coroutines.cc (morph_fn_to_coro): Remove unnecessary calls
to convert_to_reference and convert_from_reference for *this.
gcc/testsuite/ChangeLog:
* g++.dg/coroutines/pr104981-preview-this.C: New test.
* g++.dg/coroutines/pr115550-preview-this.C: New test.
---
gcc/cp/coroutines.cc | 10 +---
.../g++.dg/coroutines/pr104981-preview-this.C | 34 ++++++++++++++
.../g++.dg/coroutines/pr115550-preview-this.C | 47 +++++++++++++++++++
3 files changed, 82 insertions(+), 9 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/coroutines/pr104981-preview-this.C
create mode 100644 gcc/testsuite/g++.dg/coroutines/pr115550-preview-this.C
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index f350fc33e9b..b8a53182c38 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -4622,11 +4622,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree
*destroyer)
/* We pass a reference to *this to the allocator lookup. */
tree tt = TREE_TYPE (TREE_TYPE (arg));
tree this_ref = build1 (INDIRECT_REF, tt, arg);
The patch is OK.
Maybe also simplify these two lines (in both places) to
cp_build_fold_indirect_ref, while we're here?
Jason