| 1 |
// P0847R7 |
| 2 |
// { dg-do compile { target c++23 } } |
| 3 |
// { dg-options "-pedantic-errors -Wno-volatile" } |
| 4 |
|
| 5 |
// rejecting redeclarations of by-value xobj member functions |
| 6 |
// as iobj member functions that are not ref qualified (and vice-versa) |
| 7 |
// also check that valid overloads are accepted without diagnostic |
| 8 |
|
| 9 |
// iobj | xobj | MSVC | clang | ISOC++ |
| 10 |
// none | none | X | X | X |
| 11 |
// none | c | X | O | X |
| 12 |
// none | v | X | O | X |
| 13 |
// none | cv | X | O | X |
| 14 |
// c | none | O | O | O |
| 15 |
// c | c | O | X | O |
| 16 |
// c | v | O | O | O |
| 17 |
// c | cv | O | O | O |
| 18 |
// v | none | O | O | O |
| 19 |
// v | c | O | O | O |
| 20 |
// v | v | O | X | O |
| 21 |
// v | cv | O | O | O |
| 22 |
// cv | none | O | O | O |
| 23 |
// cv | c | O | O | O |
| 24 |
// cv | v | O | O | O |
| 25 |
// cv | cv | O | X | O |
| 26 |
|
| 27 |
/* Top-level cv qualifiers are supposed to be discarded from |
| 28 |
the parameters of a function declaration. |
| 29 |
|
| 30 |
[dcl.fct.5] |
| 31 |
After producing the list of parameter types, any top-level |
| 32 |
cv-qualifiers modifying a parameter type are deleted when forming |
| 33 |
the function type. |
| 34 |
|
| 35 |
According to the standard, the type of an implicit object parameter |
| 36 |
is always a reference. This isn't reflected in GCC but we still need |
| 37 |
to take this rule into account here. |
| 38 |
|
| 39 |
[over.match.funcs.general.4] |
| 40 |
For implicit object member functions, the type of the implicit |
| 41 |
object parameter is |
| 42 |
-- “lvalue reference to cv X” for functions declared |
| 43 |
without a ref-qualifier or with the & ref-qualifier |
| 44 |
-- “rvalue reference to cv X” for functions declared with |
| 45 |
the && ref-qualifier |
| 46 |
|
| 47 |
When comparing an iobj and xobj member function to see if they are |
| 48 |
redeclarations we treat them differently depending on if the iobj |
| 49 |
member function has a ref qualifier or not. |
| 50 |
If the iobj member function does not have a ref qualifier, we need to |
| 51 |
strip the top-level references before comparing them. |
| 52 |
|
| 53 |
[basic.scope.scope.3] |
| 54 |
Two non-static member functions have corresponding object |
| 55 |
parameters if: |
| 56 |
-- exactly one is an implicit object member function with no |
| 57 |
ref-qualifier and the types of their object parameters |
| 58 |
([dcl.fct]), after removing top-level references, are the |
| 59 |
same, or |
| 60 |
-- their object parameters have the same type. */ |
| 61 |
|
| 62 |
struct S { |
| 63 |
void f0(); // { dg-note "previous declaration" } |
| 64 |
void f0(this S); // { dg-error "cannot be overloaded with" } |
| 65 |
|
| 66 |
void f1(); // { dg-note "previous declaration" } |
| 67 |
void f1(this S const); // { dg-error "cannot be overloaded with" } |
| 68 |
|
| 69 |
void f2(); // { dg-note "previous declaration" } |
| 70 |
void f2(this S volatile); // { dg-error "cannot be overloaded with" } |
| 71 |
|
| 72 |
void f3(); // { dg-note "previous declaration" } |
| 73 |
void f3(this S const volatile); // { dg-error "cannot be overloaded with" } |
| 74 |
|
| 75 |
void fc0() const; // { dg-bogus "" } |
| 76 |
void fc0(this S); // { dg-bogus "" } |
| 77 |
|
| 78 |
void fc1() const; // { dg-bogus "" } |
| 79 |
void fc1(this S const); // { dg-bogus "" } |
| 80 |
|
| 81 |
void fc2() const; // { dg-bogus "" } |
| 82 |
void fc2(this S volatile); // { dg-bogus "" } |
| 83 |
|
| 84 |
void fc3() const; // { dg-bogus "" } |
| 85 |
void fc3(this S const volatile); // { dg-bogus "" } |
| 86 |
|
| 87 |
void fv0() volatile; // { dg-bogus "" } |
| 88 |
void fv0(this S); // { dg-bogus "" } |
| 89 |
|
| 90 |
void fv1() volatile; // { dg-bogus "" } |
| 91 |
void fv1(this S const); // { dg-bogus "" } |
| 92 |
|
| 93 |
void fv2() volatile; // { dg-bogus "" } |
| 94 |
void fv2(this S volatile); // { dg-bogus "" } |
| 95 |
|
| 96 |
void fv3() volatile; // { dg-bogus "" } |
| 97 |
void fv3(this S const volatile); // { dg-bogus "" } |
| 98 |
|
| 99 |
void fcv0() const volatile; // { dg-bogus "" } |
| 100 |
void fcv0(this S); // { dg-bogus "" } |
| 101 |
|
| 102 |
void fcv1() const volatile; // { dg-bogus "" } |
| 103 |
void fcv1(this S const); // { dg-bogus "" } |
| 104 |
|
| 105 |
void fcv2() const volatile; // { dg-bogus "" } |
| 106 |
void fcv2(this S volatile); // { dg-bogus "" } |
| 107 |
|
| 108 |
void fcv3() const volatile; // { dg-bogus "" } |
| 109 |
void fcv3(this S const volatile); // { dg-bogus "" } |
| 110 |
|
| 111 |
// same as the above f cases except reversed |
| 112 |
|
| 113 |
void g0(this S); // { dg-note "previous declaration" } |
| 114 |
void g0(); // { dg-error "cannot be overloaded with" } |
| 115 |
|
| 116 |
void g1(this S const); // { dg-note "previous declaration" } |
| 117 |
void g1(); // { dg-error "cannot be overloaded with" } |
| 118 |
|
| 119 |
void g2(this S volatile); // { dg-note "previous declaration" } |
| 120 |
void g2(); // { dg-error "cannot be overloaded with" } |
| 121 |
|
| 122 |
void g3(this S const volatile); // { dg-note "previous declaration" } |
| 123 |
void g3(); // { dg-error "cannot be overloaded with" } |
| 124 |
|
| 125 |
void gc0(this S); // { dg-bogus "" } |
| 126 |
void gc0() const; // { dg-bogus "" } |
| 127 |
|
| 128 |
void gc1(this S const); // { dg-bogus "" } |
| 129 |
void gc1() const; // { dg-bogus "" } |
| 130 |
|
| 131 |
void gc2(this S volatile); // { dg-bogus "" } |
| 132 |
void gc2() const; // { dg-bogus "" } |
| 133 |
|
| 134 |
void gc3(this S const volatile); // { dg-bogus "" } |
| 135 |
void gc3() const; // { dg-bogus "" } |
| 136 |
|
| 137 |
void gv0(this S); // { dg-bogus "" } |
| 138 |
void gv0() volatile; // { dg-bogus "" } |
| 139 |
|
| 140 |
void gv1(this S const); // { dg-bogus "" } |
| 141 |
void gv1() volatile; // { dg-bogus "" } |
| 142 |
|
| 143 |
void gv2(this S volatile); // { dg-bogus "" } |
| 144 |
void gv2() volatile; // { dg-bogus "" } |
| 145 |
|
| 146 |
void gv3(this S const volatile); // { dg-bogus "" } |
| 147 |
void gv3() volatile; // { dg-bogus "" } |
| 148 |
|
| 149 |
void gcv0(this S); // { dg-bogus "" } |
| 150 |
void gcv0() const volatile; // { dg-bogus "" } |
| 151 |
|
| 152 |
void gcv1(this S const); // { dg-bogus "" } |
| 153 |
void gcv1() const volatile; // { dg-bogus "" } |
| 154 |
|
| 155 |
void gcv2(this S volatile); // { dg-bogus "" } |
| 156 |
void gcv2() const volatile; // { dg-bogus "" } |
| 157 |
|
| 158 |
void gcv3(this S const volatile); // { dg-bogus "" } |
| 159 |
void gcv3() const volatile; // { dg-bogus "" } |
| 160 |
}; |
| 161 |
|