From 46e2f1e64b969b50fdd3f00f875f7c164959c137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 28 Jun 2010 15:33:27 +0200 Subject: [PATCH] --author=Robert Reif Fixed #1814 (false positive: Variable hides typedef with same name) --- lib/tokenize.cpp | 2 +- test/testsimplifytokens.cpp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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() { {