Repository navigation
Fix #15126 FP syntaxError (function try block with override in struct) - #8955
chrchr-github wants to merge 2 commits into
Conversation
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
The fix works for the common forms, void f() [const|noexcept|noexcept(true)] override|final try {...} catch(...) {...}, and I found no regressions. It only handles a single override or final directly after ) or after a keyword, though. Two forms with override still give the same syntaxError:
- a ref-qualifier:
void i() & override try,void i() && override try,void i() const & override try - a trailing return type:
auto k() -> void override try
The base version fails on these forms without override as well (void i() & try, auto k() -> void try), so they are a gap that already existed rather than a regression. It is still a gap in the same ticket area. When final or override is used as a variable name before a try inside a function body, the PR gives no new false positive.
Testing
I built cppcheck and testrunner in pr/. ./testrunner TestTokenizer TestGarbage TestSymbolDatabase TestSimplifyTokens TestClass passed with 0 failures.
Handled correctly, no errors:
const overridenoexcept overridenoexcept(true) overrideoverride finalint final = 0; try {...}inside a function bodyint override[2]; ... try {...}inside a function body
Still syntaxError, ./cppcheck -q x.cpp in each case:
struct E : B {
void i() & override try {} catch (...) {}
};error: syntax error: keyword 'try' is not allowed in class/struct/union/enum scope [syntaxError]
These forms give the same error:
void i() && override try {} catch (...) {}void i() const & override try {} catch (...) {}auto k() -> void override try {} catch (...) {}
Without override, the base version also rejects void i() & try {} catch (...) {} and auto k() -> void try {} catch (...) {}, so this limitation existed before the PR.
Automated review of aa91b3a by Claude. The pull request was built and tested locally.
| continue; | ||
| const Token* par = tok->previous(); | ||
| while (par && par->isKeyword()) | ||
| while (par && (par->isKeyword() || Token::Match(par, "final|override"))) |
There was a problem hiding this comment.
AI review
This loop still misses override or final after a ref-qualifier or a trailing return type. These still produce syntaxError:
struct E : B { void i() & override try {} catch (...) {} };
struct F : B { auto k() -> void override try {} catch (...) {} };&/&& and -> type before try already fail in base without override, so this is a gap that existed before, not a regression. It may still be worth covering here, or noting in the ticket.
|
Test results for commit aa91b3a (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-8955/ Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong. |
No description provided.