Skip to content

Explicit object operator() copies movable temporaries #100542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Fedr opened this issue Jul 25, 2024 · 2 comments
Closed

Explicit object operator() copies movable temporaries #100542

Fedr opened this issue Jul 25, 2024 · 2 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate

Comments

@Fedr
Copy link

Fedr commented Jul 25, 2024

This program

struct A {
    A() {}
    A(A&&) = default;
    void operator() (this A) {}
};

int main() {
    A{}.operator()(); // ok
    A{}();            // fails in Clang
}

is accepted by GCC and MSVC, but not in Clang, which tries to copy A in A{}();:

error: call to implicitly-deleted copy constructor of 'A'
    9 |     A{}();            // fails in Clang
      |     ^~~
<source>:3:5: note: copy constructor is implicitly deleted because 'A' has a user-declared move constructor
    3 |     A(A&&) = default;
      |     ^
<source>:4:28: note: passing argument to parameter here
    4 |     void operator() (this A) {}
      |               

Online demo: https://gcc.godbolt.org/z/YEKh8G71o

@MitalAshok
Copy link
Contributor

Duplicate of #100341

@EugeneZelenko EugeneZelenko added duplicate Resolved as duplicate clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Jul 25, 2024
@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2024

@llvm/issue-subscribers-clang-frontend

Author: Fedor Chelnokov (Fedr)

This program ``` struct A { A() {} A(A&&) = default; void operator() (this A) {} };

int main() {
A{}.operator()(); // ok
A{}(); // fails in Clang
}

is accepted by GCC and MSVC, but not in Clang, which tries to copy `A` in `A{}();`:

error: call to implicitly-deleted copy constructor of 'A'
9 | A{}(); // fails in Clang
| ^~~
<source>:3:5: note: copy constructor is implicitly deleted because 'A' has a user-declared move constructor
3 | A(A&&) = default;
| ^
<source>:4:28: note: passing argument to parameter here
4 | void operator() (this A) {}
|

Online demo: https://gcc.godbolt.org/z/YEKh8G71o
</details>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants