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

Sometimes incorrect parse of C(C&) #24

Open
paul-j-lucas opened this issue Oct 11, 2022 · 0 comments
Open

Sometimes incorrect parse of C(C&) #24

paul-j-lucas opened this issue Oct 11, 2022 · 0 comments

Comments

@paul-j-lucas
Copy link
Owner

A declaration like:

c++decl> explain C(C const&)
declare C as constructor (reference to constant C)

(where C has not been predeclared) works because the lexer returns C as a NAME and the parser matches it here:

pc99_func_or_constructor_decl_c
  : Y_NAME '(' param_list_c_ast_opt ')' noexcept_c_stid_opt func_equals_c_stid_opt

In C++, a NAME followed by ( declares an in-class constructor, so we interpret it as such.

However, if C is predeclared, then it doesn't work:

c++decl> class C
c++decl> explain C(C const&)
                          ^
12: syntax error: "&": ')' expected

The reason is because the lexer returns C as a type name and the parser tries to match it here:

typed_declaration_c
  : type_c_ast decl_list_c_opt

as an ordinary typed declaration (which is wrong). The reason is because C++ grammar is ambiguous:

C(x)    // declare x as C (with unnecessary parentheses)
C(C&)   // declare C as constructor

There's no easy fix for this.

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

1 participant