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.
This commit is contained in:
Patrick Palka 2021-07-16 16:21:10 -04:00
parent 9faf834862
commit d04b0c7579
2 changed files with 21 additions and 1 deletions

View File

@ -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);

View File

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