As explained in one of Tomasz's library papers P2438R2[1], C++20 allows
ref-qualified member overloads to coexist with non-ref-qualified ones,
but at the time of writing no compiler supported that. This patch
implements this C++20 relaxation so that we can in turn implement
P2438R2 as originally intended -- without needing to change the
signature of the main string::substr overload.
[1]: https://wg21.link/P2438R2#_modifying_existing_const_overload
PR c++/98939
PR libstdc++/119745
gcc/cp/ChangeLog:
* class.cc (object_parms_correspond): Allow differing
FUNCTION_REF_QUALIFIED in C++20.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/ref-qual5.C: Expect no diagnostics in C++20.
Reviewed-by: Jason Merrill <jason@redhat.com>
&& DECL_IOBJ_MEMBER_FUNCTION_P (method))
{
/* Either both or neither need to be ref-qualified for
- differing quals to allow overloading. */
- if ((FUNCTION_REF_QUALIFIED (fn_type)
- == FUNCTION_REF_QUALIFIED (method_type))
+ differing quals to allow overloading before C++20 (P1787R6). */
+ if ((cxx_dialect >= cxx20
+ || (FUNCTION_REF_QUALIFIED (fn_type)
+ == FUNCTION_REF_QUALIFIED (method_type)))
&& (type_memfn_quals (fn_type) != type_memfn_quals (method_type)
|| type_memfn_rqual (fn_type) != type_memfn_rqual (method_type)))
return false;
// 13.1: ...cannot be overloaded if any of them, but not all, have a
// ref-qualifier.
+// In C++20 this was relaxed by P1787R6 "Declarations and where to find them"
// { dg-require-effective-target c++11 }
void h() &;
void h() const &; // OK
void h() &&; // OK, all declarations have a ref-qualifier
- void i() &; // { dg-message "" }
- void i() const; // { dg-error "" } prior declaration of i
- // has a ref-qualifier
+ void i() &; // { dg-message "" "" { target c++17_down } }
+ void i() const; // { dg-error "" "" { target c++17_down } }
+ // prior declaration of i has a ref-qualifier
};