diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 12aec26a005..441f1492d2e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8979,7 +8979,10 @@ void Tokenizer::simplifyFunctionTryCatch() for (Token * tok = list.front(); tok; tok = tok->next()) { if (!Token::Match(tok, "try {|:")) continue; - if (!TokenList::isFunctionHead(tok->previous(), "try")) // TODO: this is supposed to a list of characters and not strings + const Token* par = tok->previous(); + while (par && par->isKeyword()) + par = par->previous(); + if (!TokenList::isFunctionHead(par, "try")) // TODO: this is supposed to a list of characters and not strings continue; Token* tryStartToken = skipInitializerList(tok->next()); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 8b97a4960fc..6af2b140989 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -1817,6 +1817,15 @@ class TestTokenizer : public TestFixture { " };\n" "} catch (long) {\n" "}")); + + ASSERT_EQUALS("struct S { void func ( ) const ; } ;\n" + "void S :: func ( ) const {\n" + "try { f ( ) ; }\n" + "catch ( ... ) { g ( ) ; } }", + tokenizeAndStringify("struct S { void func() const; };\n" + "void S::func() const\n" + "try { f(); }\n" + "catch (...) { g(); }\n")); } // Simplify "((..))" into "(..)"