public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2377] c++: covariant reference return types [PR99664]
@ 2021-07-16 20:21 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2021-07-16 20:21 UTC (permalink / raw)
  To: gcc-cvs

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" }
+};


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-16 20:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-16 20:21 [gcc r12-2377] c++: covariant reference return types [PR99664] Patrick Palka

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).