public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-6846] c++: value category of compound object expr [PR104173]
Date: Mon, 24 Jan 2022 14:17:54 +0000 (GMT)	[thread overview]
Message-ID: <20220124141754.4508C385801E@sourceware.org> (raw)

https://gcc.gnu.org/g:2a908f3da07c9e94b8a19e966b45daf0140107e8

commit r12-6846-g2a908f3da07c9e94b8a19e966b45daf0140107e8
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Jan 24 09:17:35 2022 -0500

    c++: value category of compound object expr [PR104173]
    
    Here the call to (the &&-qualified) toLower() is incorrectly rejected
    during overload resolution because the object expression is encoded as
    an lvalue when it's really a prvalue.  The object expression,
    instance()->applicationName(), is encoded as an INDIRECT_REF of a
    COMPOUND_EXPR
    
      *(*instance ();, &TARGET_EXPR <D.2383, QCoreApplication::applicationName ()>;);
    
    which lvalue_kind deems an lvalue.
    
    This issue is similar to PR88103 except that here the original compound
    object expression is a prvalue rather than an xvalue.  The fix there was to
    adjust the result of unary_complex_lvalue in build_class_member_access_expr
    so that xvalueness of the original expression is preserved.  This patch
    extends that fix so that rvalueness is preserved more generally.
    
            PR c++/104173
    
    gcc/cp/ChangeLog:
    
            * typeck.cc (build_class_member_access_expr): Extend
            unary_complex_lvalue result adjustment to preserve all
            rvalues, not just xvalues.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp0x/ref-qual21.C: New test.

Diff:
---
 gcc/cp/typeck.cc                        | 19 ++++++++-----------
 gcc/testsuite/g++.dg/cpp0x/ref-qual21.C | 23 +++++++++++++++++++++++
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 3a28d639cb1..11c9d8aff3e 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -2726,17 +2726,14 @@ build_class_member_access_expr (cp_expr object, tree member,
   /* Transform `(a, b).x' into `(*(a, &b)).x', `(a ? b : c).x' into
      `(*(a ?  &b : &c)).x', and so on.  A COND_EXPR is only an lvalue
      in the front end; only _DECLs and _REFs are lvalues in the back end.  */
-  {
-    tree temp = unary_complex_lvalue (ADDR_EXPR, object);
-    if (temp)
-      {
-	temp = cp_build_fold_indirect_ref (temp);
-	if (xvalue_p (object) && !xvalue_p (temp))
-	  /* Preserve xvalue kind.  */
-	  temp = move (temp);
-	object = temp;
-      }
-  }
+  if (tree temp = unary_complex_lvalue (ADDR_EXPR, object))
+    {
+      temp = cp_build_fold_indirect_ref (temp);
+      if (!lvalue_p (object) && lvalue_p (temp))
+	/* Preserve rvalueness.  */
+	temp = move (temp);
+      object = temp;
+    }
 
   /* In [expr.ref], there is an explicit list of the valid choices for
      MEMBER.  We check for each of those cases here.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/ref-qual21.C b/gcc/testsuite/g++.dg/cpp0x/ref-qual21.C
new file mode 100644
index 00000000000..7f867c21706
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/ref-qual21.C
@@ -0,0 +1,23 @@
+// PR c++/104173
+// { dg-do compile { target c++11 } }
+
+struct QString {
+  QString toLower() &&;
+};
+
+struct QCoreApplication {
+  static QString applicationName();
+};
+
+QCoreApplication* instance();
+
+void f() {
+  instance()->applicationName().toLower();
+}
+
+template<class...>
+void g() {
+  instance()->applicationName().toLower();
+}
+
+template void g<>();


                 reply	other threads:[~2022-01-24 14:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220124141754.4508C385801E@sourceware.org \
    --to=ppalka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).