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-2377] c++: covariant reference return types [PR99664]
Date: Fri, 16 Jul 2021 20:21:36 +0000 (GMT)	[thread overview]
Message-ID: <20210716202136.EA869383D019@sourceware.org> (raw)

https://gcc.gnu.org/g:d04b0c75794545f1f7a942764285e21eaf2915a1

commit r12-2377-gd04b0c75794545f1f7a942764285e21eaf2915a1
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Jul 16 16:21:10 2021 -0400

    c++: covariant reference return types [PR99664]
    
    This implements the wording changes of CWG 960 which clarifies that two
    reference types are covariant only if they're both lvalue references
    or both rvalue references.
    
            DR 960
            PR c++/99664
    
    gcc/cp/ChangeLog:
    
            * search.c (check_final_overrider): Compare TYPE_REF_IS_RVALUE
            when the return types are references.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/inherit/covariant23.C: New test.

Diff:
---
 gcc/cp/search.c                            |  8 +++++++-
 gcc/testsuite/g++.dg/inherit/covariant23.C | 14 ++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index af41bfe5835..943671acff8 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -1948,7 +1948,13 @@ check_final_overrider (tree overrider, tree basefn)
       fail = !INDIRECT_TYPE_P (base_return);
       if (!fail)
 	{
-	  fail = cp_type_quals (base_return) != cp_type_quals (over_return);
+	  if (cp_type_quals (base_return) != cp_type_quals (over_return))
+	    fail = 1;
+
+	  if (TYPE_REF_P (base_return)
+	      && (TYPE_REF_IS_RVALUE (base_return)
+		  != TYPE_REF_IS_RVALUE (over_return)))
+	    fail = 1;
 
 	  base_return = TREE_TYPE (base_return);
 	  over_return = TREE_TYPE (over_return);
diff --git a/gcc/testsuite/g++.dg/inherit/covariant23.C b/gcc/testsuite/g++.dg/inherit/covariant23.C
new file mode 100644
index 00000000000..b27be15ef45
--- /dev/null
+++ b/gcc/testsuite/g++.dg/inherit/covariant23.C
@@ -0,0 +1,14 @@
+// PR c++/99664
+// { dg-do compile { target c++11 } }
+
+struct Res { };
+
+struct A {
+  virtual Res &&f();
+  virtual Res &g();
+};
+
+struct B : A {
+  Res &f() override; // { dg-error "return type" }
+  Res &&g() override; // { dg-error "return type" }
+};


                 reply	other threads:[~2021-07-16 20:21 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=20210716202136.EA869383D019@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).