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] Accepts invalid constructor declaration with an asterisk #121706

Closed
MagentaTreehouse opened this issue Jan 5, 2025 · 4 comments · Fixed by #122621
Closed

[Clang] Accepts invalid constructor declaration with an asterisk #121706

MagentaTreehouse opened this issue Jan 5, 2025 · 4 comments · Fixed by #122621
Labels
accepts-invalid clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@MagentaTreehouse
Copy link
Contributor

struct A {
    *A();
};

See Compiler Explorer: https://compiler-explorer.com/z/ccf6rqenE

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jan 5, 2025
@pinskia
Copy link

pinskia commented Jan 5, 2025

Just FYI, GCC has a similar bug and was filed as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118306 (there was also a recent regression with an ICE when defaulting the constructor which the reporter here reported to GCC as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118304 ).

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" accepts-invalid and removed clang Clang issues not falling into any other category labels Jan 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 6, 2025

@llvm/issue-subscribers-clang-frontend

Author: None (MagentaTreehouse)

```c++ struct A { *A(); }; ``` See Compiler Explorer: https://compiler-explorer.com/z/ccf6rqenE

@shafik
Copy link
Collaborator

shafik commented Jan 7, 2025

Fun to note it accepts any number of asterisks: https://compiler-explorer.com/z/naaP75err

struct A {
    ******************A();
};

we can bring the whole gang along: https://compiler-explorer.com/z/TY8aq8G9W

struct A {
    ****A();
    ***~A();
    **A(const A&);
    *A(A&&);
};

goes back to clang-2.6: https://compiler-explorer.com/z/zWv4b45s7

@MagentaTreehouse
Copy link
Contributor Author

MagentaTreehouse commented Jan 12, 2025

To generalize further, Clang seems to allow any of the ptr-operators in the ptr-declarator for constructors and destructors.

Consider also these accepts-invalid cases: https://compiler-explorer.com/z/qdbdsjbWh

struct A {
    *&A();
};

struct B {
    *&&B();
};

struct C {
    *const C();
};

struct D {
    *const *D();
};

struct E {
    *E::*E();
};

struct F {
    *F::*const F();
};

Only to fail when there is a & in the front:

struct G {
    &G();
};

Output:

<source>:2:5: error: cannot form a reference to 'void'
    2 |     &G();
      |     ^

DKLoehr pushed a commit to DKLoehr/llvm-project that referenced this issue Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepts-invalid clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
5 participants