Skip to content

Commit 695c377

Browse files
Fix #13742 FP syntaxError for function-level try block in const member function (#7413)
1 parent 29f3e0b commit 695c377

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/tokenize.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -8983,7 +8983,10 @@ void Tokenizer::simplifyFunctionTryCatch()
89838983
for (Token * tok = list.front(); tok; tok = tok->next()) {
89848984
if (!Token::Match(tok, "try {|:"))
89858985
continue;
8986-
if (!TokenList::isFunctionHead(tok->previous(), "try")) // TODO: this is supposed to a list of characters and not strings
8986+
const Token* par = tok->previous();
8987+
while (par && par->isKeyword())
8988+
par = par->previous();
8989+
if (!TokenList::isFunctionHead(par, "try")) // TODO: this is supposed to a list of characters and not strings
89878990
continue;
89888991

89898992
Token* tryStartToken = skipInitializerList(tok->next());

test/testtokenize.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,15 @@ class TestTokenizer : public TestFixture {
18171817
" };\n"
18181818
"} catch (long) {\n"
18191819
"}"));
1820+
1821+
ASSERT_EQUALS("struct S { void func ( ) const ; } ;\n"
1822+
"void S :: func ( ) const {\n"
1823+
"try { f ( ) ; }\n"
1824+
"catch ( ... ) { g ( ) ; } }",
1825+
tokenizeAndStringify("struct S { void func() const; };\n"
1826+
"void S::func() const\n"
1827+
"try { f(); }\n"
1828+
"catch (...) { g(); }\n"));
18201829
}
18211830

18221831
// Simplify "((..))" into "(..)"

0 commit comments

Comments
 (0)