diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d76757589..9f2535e32 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10044,7 +10044,7 @@ void Tokenizer::removeUnnecessaryQualification() classInfo.pop_back(); else if (tok->str() == classInfo.back().className && Token::Match(tok, "%type% :: %type% (") && - Token::Match(tok->tokAt(3)->link(), ") const| {|;") && + Token::Match(tok->tokAt(3)->link(), ") const| {|;|:") && tok->previous()->str() != ":" && !classInfo.back().isNamespace) { std::string qualification = tok->str() + "::"; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index c03d197d4..4cf1064ce 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -360,6 +360,7 @@ private: TEST_CASE(removeUnnecessaryQualification4); TEST_CASE(removeUnnecessaryQualification5); TEST_CASE(removeUnnecessaryQualification6); // ticket #2859 + TEST_CASE(removeUnnecessaryQualification7); // ticket #2970 TEST_CASE(simplifyIfNotNull); TEST_CASE(simplifyVarDecl1); // ticket # 2682 segmentation fault @@ -7221,6 +7222,18 @@ private: ASSERT_EQUALS("", errout.str()); } + void removeUnnecessaryQualification7() // ticket #2970 + { + const char code[] = "class TProcedure {\n" + "public:\n" + " TProcedure::TProcedure(long endAddress) : m_lEndAddr(endAddress){}\n" + "private:\n" + " long m_lEndAddr;\n" + "}\n"; + tok(code, false); + ASSERT_EQUALS("[test.cpp:3]: (portability) Extra qualification 'TProcedure::' unnecessary and considered an error by many compilers.\n", errout.str()); + } + void simplifyIfNotNull() { {