-
Notifications
You must be signed in to change notification settings - Fork 260
[BUG] Cppfront reports incorrect errors when a multi-statement function has no enclosing braces #946
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
Comments
They both look correct to me. |
Is there any risk to parsing one more statement to diagnose this? |
Yeah, you're right. Here's an example only with Cpp2 code:
Error: |
For context, I was playing with the
And I added a local variable at the top:
And then received the error about |
Right, at the end of a top-level Cpp2 declaration, if there isn't the start of another Cpp2 declaration we assume it's Cpp1 code and switch back to Cpp1 code. To give a different error on that would require a more fundamental change to how we recognize Cpp1/Cpp2 code which is the earliest stage of processing. However, if it's nested inside a Cpp2 region such as a namespace, you do get a better error already:
This program already got this error, which I think was fairly decent:
But with the above commit, it now gives this better message:
Again, this only fires if it's not a global function. |
Well, there was, for #907.
The tentative parsing breaks the name lookup for #907's name lookup certainly needs work. |
Describe the bug
Cppfront reports an incorrect error when parsing an ill-formed multi-statement function missing its enclosing braces.
To Reproduce
Run cppfront on this ill-formed code:
Godbolt
Cppfront reports:
error: local variable message is not used; consider changing its name to '_' to make it explicitly anonymous, or removing it entirely if its side effects are not needed
Another:
Godbolt
Cppfront reports:
error: pure-cpp2 switch disables Cpp1 syntax
But in these cases I'd expect a syntax error indicating the block is missing.
The text was updated successfully, but these errors were encountered: