From 1713eeb532ad96232e8d676fa85403f472c87c6e Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sun, 26 Jun 2011 21:13:29 -0400 Subject: [PATCH] fix #2859 (Extra qualification not detected) --- lib/tokenize.cpp | 4 ++-- test/testsimplifytokens.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index eda0aa41b..0d0ddd9ec 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9829,9 +9829,9 @@ void Tokenizer::removeUnnecessaryQualification() if (Token::Match(tok, "class|struct|namespace %type% :|{") && (!tok->previous() || (tok->previous() && tok->previous()->str() != "enum"))) { - tok = tok->next(); Space info; info.isNamespace = tok->str() == "namespace"; + tok = tok->next(); info.className = tok->str(); tok = tok->next(); while (tok && tok->str() != "{") @@ -9848,7 +9848,7 @@ void Tokenizer::removeUnnecessaryQualification() else if (tok->str() == classInfo.back().className && Token::Match(tok, "%type% :: %type% (") && Token::Match(tok->tokAt(3)->link(), ") const| {|;") && - tok->previous()->str() != ":") + tok->previous()->str() != ":" && !classInfo.back().isNamespace) { std::string qualification = tok->str() + "::"; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index dd59165db..6c8dcdaee 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -354,6 +354,7 @@ private: TEST_CASE(removeUnnecessaryQualification3); TEST_CASE(removeUnnecessaryQualification4); TEST_CASE(removeUnnecessaryQualification5); + TEST_CASE(removeUnnecessaryQualification6); // ticket #2859 TEST_CASE(simplifyIfNotNull); TEST_CASE(simplifyVarDecl1); // ticket # 2682 segmentation fault @@ -7051,6 +7052,22 @@ private: ASSERT_EQUALS("[test.cpp:11]: (portability) Extra qualification 'two::c::' unnecessary and considered an error by many compilers.\n", errout.str()); } + void removeUnnecessaryQualification6() + { + const char code[] = "namespace NS {\n" + " int HRDF_bit() { return 1; }\n" + " void HRDF_bit_set() { }\n" + " void func(int var) {\n" + " if (!NS::HRDF_bit())\n" + " return;\n" + " else\n" + " NS::HRDF_bit_set();\n" + " }\n" + "}\n"; + tok(code, false); + ASSERT_EQUALS("", errout.str()); + } + void simplifyIfNotNull() { {