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

Non-static opCall hides struct and union default constructors #20927

Open
MetaLang opened this issue Feb 28, 2025 · 1 comment
Open

Non-static opCall hides struct and union default constructors #20927

MetaLang opened this issue Feb 28, 2025 · 1 comment
Assignees

Comments

@MetaLang
Copy link
Member

MetaLang commented Feb 28, 2025

struct Test
{
    Test opCall()
    {
        return Test();
    }
}

void main()
{
    Test(); // Error: calling non-static function `opCall` requires an instance of type `Test`
}

The call Test(); in the main function should be interpreted as default construction of a new Test instance. However, it is incorrectly interpreted as a static call to the non-static opCall defined in Test.

Note that this does not occur for classes, due to the required use of the new keyword to construct them.

If the struct or a union defines a no-arg constructor, the compiler will correctly interpret Test() as a call to an illegal no-arg constructor and report an error. If it defines an N-arg constructor, the compiler will interpret Test() as a new default-initialized instance of Test.

@Gauravsh-24
Copy link

Hello @MetaLang
I would like to work on this issue. can you please assign to me.

This was referenced Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants