You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Cppfront reports incorrect errors when a multi-statement function has no enclosing braces #946
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
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:
demo.cpp2(4,9): error: a namespace scope must contain only declarations or 'using' statements, not other code
But with the above commit, it now gives this better message:
demo.cpp2(4,9): error: in this scope, a single-statement function body cannot be immediately followed by a statement - did you forget to put { } braces around a multi-statement function body?
Again, this only fires if it's not a global function.
Activity
bluetarpmedia commentedon Jan 17, 2024
Yeah, you're right. Here's an example only with Cpp2 code:
Error:
error: local variable s is not used...bluetarpmedia commentedon Jan 17, 2024
For context, I was playing with the
pure2-main-args.cpp2regression test, which looks like this:And I added a local variable at the top:
And then received the error about
messagebeing unused, which confused me until I realized the block was missing.hsutter commentedon Jan 18, 2024
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.