This is not possible.
When you have two candidate functions like these, the overload taking an lvalue reference to function type is always preferred over the rvalue reference overload. Functions are considered lvalues in all cases so the conversion to an lvalue reference is the strongest. Here is some standard wording ([over.ics.rank]/p3.2.4):
Standard conversion sequence S1
is a better conversion sequence than standard conversion sequence S2
if
S1 and S2 are reference bindings (8.5.3) and S1 binds an lvalue reference to a function lvalue and S2
binds an rvalue reference to a function lvalue. [ Example:
int f(void(&)()); // #1
int f(void(&&)()); // #2
void g();
int i1 = f(g); // calls #1
— end example]
The code from my comment presented here calls overload #2 in gcc and is rejected by clang.
void foo(void(&)(int)); // #1
void foo(void(&&)(int)); // #2
void f(int);
struct wrap {
using T = void(&&)(int);
operator T() { return f; }
};
int main() {
foo(wrap{}); // Calls #2 in gcc, error in clang
}
The Clang error is:
non-const lvalue reference to type void (int)
cannot bind to a temporary of type wrap
GCC is obviously wrong because of the above quote, but Clang is also wrong as well. The result of the operator function is an lvalue so it should bind to the lvalue overload, but it seems that clang is not attempting the conversion. A simpler example is:
void (&r)(int) = wrap{}; // OK in gcc, error in clang
So this looks like a bug in Clang and GCC.