Yes it is valid. Cppcheck should handle it. I think it looks weird but feel free to use whatever constructs you like in your code. If you have time to fix this in Cppcheck, feel free to do it. I would add a pass in our tokenizer that inserts extra { and } tokens, that should be relatively simple and quick.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
the latest cppcheck exits with a syntax error on this valid code:
int main(int argc, char **argv) try
{
return 0;
}
catch (Error &e)
{
return 1;
}
error: syntax error: keyword 'try' is not allowed in global scope [syntaxError]
int main(int argc, char **argv) try
See f.e.: https://stackoverflow.com/questions/8405390/function-try-catch-syntax-and-main
Could you please check?
Thanks,
Martin
Sorry, already seems to handled by:
https://trac.cppcheck.net/ticket/9728
https://trac.cppcheck.net/ticket/9716
A stylistic question. Why not add extra semicolons to make it more readable?
I don't think I've ever seen such syntax in real code. Is this from real production code?
Yes, we have examples of that in our production code, and it's a valid C++ construct:
https://en.cppreference.com/w/cpp/language/function-try-block
Yes it is valid. Cppcheck should handle it. I think it looks weird but feel free to use whatever constructs you like in your code. If you have time to fix this in Cppcheck, feel free to do it. I would add a pass in our tokenizer that inserts extra
{
and}
tokens, that should be relatively simple and quick.Hi,
Is there any workaround regarding this issue?
The error code is syntaxError, can I suppress syntaxError using the command line parameters?
syntaxError is handled by the compiler so I think it's OK to suppress it until it will be fixed in cppcheck.
to suppress it: