mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-24 03:14:08 +08:00
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:
parent
9faf834862
commit
d04b0c7579
@ -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);
|
||||
|
14
gcc/testsuite/g++.dg/inherit/covariant23.C
Normal file
14
gcc/testsuite/g++.dg/inherit/covariant23.C
Normal 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" }
|
||||
};
|
Loading…
Reference in New Issue
Block a user