Explicit object parameter and using-declarations
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Consider the following example:
```cpp
struct B {
void usingNoRef_this() = delete;
void this_usingNoRef() = delete;
};
struct D : B {
using B::usingNoRef_this;
void usingNoRef_this(this D) {};
void this_usingNoRef(this D) {};
using B::this_usingNoRef;
};
void test(D& d)
{
d.usingNoRef_this(); // #1, accepted
d.this_usingNoRef(); // #2, ambiguous call
}
```
This and four more cases are available on Complier Explorer ([link](https://godbolt.org/z/94dvEv1h1)).
All calls should be accepted, like GCC does, per [[namespace.udecl]/11](https://eel.is/c++draft/namespace.udecl#11):
> The set of declarations named by a [using-declarator](https://eel.is/c++draft/namespace.udecl#nt:using-declarator) that inhabits a class C does not include member functions and member function templates of a base class that, when considered as members of C, correspond to a declaration of a function or function template in C[.](https://eel.is/c++draft/namespace.udecl#11.sentence-1)
Pairs of function declarations above are corresponding overloads (and thus correspond), because type of implicit object parameters of functions declared in `B` is based on `D` per [[over.match.funcs]/4.2](https://eel.is/c++draft/over.match.funcs#general-4.sentence-4):
> For non-conversion functions that are implicit object member functions nominated by a [using-declaration](https://eel.is/c++draft/namespace.udecl#nt:using-declaration) in a derived class, the function is considered to be a member of the derived class for the purpose of defining the type of the implicit object parameter[.](https://eel.is/c++draft/over.match.funcs#general-4.sentence-4)
This was found via [exhaustive testing](https://godbolt.org/z/nGdjPG5Ps) of this design space I did during research for [CWG3103](https://github.com/cplusplus/CWG/issues/776). I'll submit full test to our conformance test suite later.
CC @cor3ntin
Contributor guide
Assessment
This issue has not been assessed yet.