diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 70ecc30da..8a721b592 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -550,7 +550,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name) // look backwards if (Token::Match(tok->previous(), "typedef|}|>|*") || (Token::Match(tok->previous(), "%type%") && - (!Token::Match(tok->previous(), "return|new|const|friend|public|private|protected") && + (!Token::Match(tok->previous(), "return|new|const|friend|public|private|protected|throw") && !Token::Match(tok->tokAt(-2), "friend class")))) { // scan backwards for the end of the previous statement diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 93fbfa128..424f0a1b6 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -204,6 +204,7 @@ private: TEST_CASE(simplifyTypedef51); TEST_CASE(simplifyTypedef52); // ticket #1782 TEST_CASE(simplifyTypedef53); // ticket #1801 + TEST_CASE(simplifyTypedef54); // ticket #1814 TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction2); // ticket #1685 @@ -4206,6 +4207,25 @@ private: } } + void simplifyTypedef54() // ticket #1814 + { + const char code[] = "void foo()\n" + "{\n" + " typedef std::basic_string string_type;\n" + " try\n" + " {\n" + " throw string_type(\"leak\");\n" + " }\n" + " catch (const string_type&)\n" + " {\n" + " pthread_exit (0);\n" + " }\n" + "}"; + + checkSimplifyTypedef(code); + ASSERT_EQUALS("", errout.str()); + } + void simplifyTypedefFunction1() { {