Question
Why does operator() copy movable temporaries in Clang?
In the following C++23 program
struct A {
A() {}
A(A&&) = default;
void f(this A) {}
void operator() (this A) {}
};
int main() {
A{}.f(); // ok
A{}(); // Clang error
}
struct A
is movable, and its member functions f()
and operator()
have explicit object parameter (this A)
.
In Clang compiler surprisingly A{}.f()
works fine, but A{}()
fails with the error:
<source>:10:5: error: call to implicitly-deleted copy constructor of 'A'
<source>:3:5: note: copy constructor is implicitly deleted because 'A' has a user-declared move constructor
Online demo: https://gcc.godbolt.org/z/hbfzMvE9f
Is there some difference between functions f()
and operator()
from the language standpoint that explains their observable treatment by the compiler?