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

[BUG] semicolons allowed in parameter list #1097

Closed
gregmarr opened this issue Jun 5, 2024 · 1 comment · Fixed by #1100
Closed

[BUG] semicolons allowed in parameter list #1097

gregmarr opened this issue Jun 5, 2024 · 1 comment · Fixed by #1100
Labels
bug Something isn't working

Comments

@gregmarr
Copy link
Contributor

gregmarr commented Jun 5, 2024

Describe the bug
Cppfront allows a semicolon at the end of each parameter, before the comma.

To Reproduce
Steps to reproduce the behavior:

  1. Sample code

Found from https://github.com/isidorostsa/RayTrayCpp2/blob/main/src/inc/camera.h2#L32, but much simpler:

func: (a: double;, b: uint;, c: double;) = {}
  1. Command lines including which C++ compiler you are using

https://cpp2.godbolt.org

  1. Expected result - what you expected to happen

Error for having a semicolon in the parameter list.

  1. Actual result/error

Success.

Additional context
I tried digging into the grammar to see where this semicolon is being allowed, but I couldn't find it.

Matching `(a: double;, b: uint;, c: double;)`
//G parameter-declaration-list:
//G     '(' parameter-declaration-seq? ','? ')' 
'(' <a: double;, b: uint;, c: double;> <> ')'

//G parameter-declaration-seq:
//G     parameter-declaration 
<a: double;>
<b: uint;>
<c: double;>
//G     parameter-declaration-seq ',' parameter-declaration
<a: double;, b: uint;> ',' <c: double;>
<a: double;> ',' <b: uint;>

//G parameter-declaration:
//G     this-specifier? parameter-direction? declaration 
<> <> <a: double;>
<> <> <b: uint;>
<> <> <c: double;>

//G declaration:
//G     access-specifier? identifier '...'? unnamed-declaration
<> <a> <> <: double;>
<> <b> <> <: uint;>
<> <c> <> <: double;>
//G     access-specifier? identifier alias
No '==' for alias, so these won't match.

//G unnamed-declaration:
//G     ':' meta-functions? template-parameters? function-type requires-clause? '=' statement
No '=', doesn't match.
//G     ':' meta-functions? template-parameters? function-type statement
No '(' for function-type, doesn't match.
//G     ':' meta-functions? template-parameters? type-id? requires-clause? '=' statement
No '=', doesn't match.
//G     ':' meta-functions? template-parameters? type-id
':' <> <> <double;>
':' <> <> <uint;>
//G     ':' meta-functions? template-parameters? 'final'? 'type' requires-clause? '=' statement
No '=', doesn't match.
//G     ':' 'namespace' '=' statement
No '=', doesn't match.

//G type-id:
//G     type-qualifier-seq? qualified-id
No '::' for qualified-id, doesn't match.
//G     type-qualifier-seq? unqualified-id
<> <double;>
<> <uint;>

//G unqualified-id:
//G     identifier
Shouldn't include ';'.
//G     keyword
Not a keyword.
//G     template-id
No '<' for template-id, doesn't match.
//GTODO     operator-function-id
//G     ...
Is this an actual grammar thing that might be picking up `double;` and `uint;`?
@gregmarr gregmarr added the bug Something isn't working label Jun 5, 2024
@sookach
Copy link
Contributor

sookach commented Jun 9, 2024

Thanks for the interesting bug and detailed report. I found the offending code, and the problem lies in the fact that parameter declarations are parsed as regular declarations (which allow a semicolon at the end). I can get a patch out pretty soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants