Skip to content
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

Clang rejects valid program when using function call operator #100547

Open
ranaanoop opened this issue Jul 25, 2024 · 3 comments
Open

Clang rejects valid program when using function call operator #100547

ranaanoop opened this issue Jul 25, 2024 · 3 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party rejects-valid

Comments

@ranaanoop
Copy link

ranaanoop commented Jul 25, 2024

The following valid program is rejected by clang: Demo

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

int main() {
    A{}.f(); // ok
    A{}();   // Clang rejects while gcc and msvc accepts 
}

As per over.call, the expression A{}() is equivalent to(interpreted as) A{}.operator()() which clang accepts.

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Jul 25, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid and removed clang Clang issues not falling into any other category labels Jul 25, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 25, 2024

@llvm/issue-subscribers-clang-frontend

Author: Anoop Rana (ranaanoop)

The following valid program is rejected by clang: [Demo](https://godbolt.org/z/rK5W6G7K8) ``` struct A { A() {} A(A&&) = default; void f(this A) {} void operator() (this A) {} };

int main() {
A{}.f(); // ok
A{}(); // Clang rejects while gcc and msvc accepts
}


As per [over.call](https://eel.is/c++draft/over.call#<!-- -->1.sentence-5), the expression `A{}()` is equivalent to(interpreted as) `A{}.operator()()` which [clang accepts](https://godbolt.org/z/eTc6b6TYq).
</details>

@shafik
Copy link
Collaborator

shafik commented Jul 25, 2024

This looks like a clang bug: https://godbolt.org/z/TK7KeEWjG

@shafik shafik added the confirmed Verified by a second party label Jul 25, 2024
@zygoloid
Copy link
Collaborator

For some reason, the this A parameter is being copied from the A{} prvalue -- the parameter should be initialized directly with the prvalue instead.

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" confirmed Verified by a second party rejects-valid
Projects
None yet
Development

No branches or pull requests

5 participants