fix #2859 (Extra qualification not detected)

This commit is contained in:
Robert Reif 2011-06-26 21:13:29 -04:00
parent 918b4d859f
commit 1713eeb532
2 changed files with 19 additions and 2 deletions

View File

@ -9829,9 +9829,9 @@ void Tokenizer::removeUnnecessaryQualification()
if (Token::Match(tok, "class|struct|namespace %type% :|{") && if (Token::Match(tok, "class|struct|namespace %type% :|{") &&
(!tok->previous() || (tok->previous() && tok->previous()->str() != "enum"))) (!tok->previous() || (tok->previous() && tok->previous()->str() != "enum")))
{ {
tok = tok->next();
Space info; Space info;
info.isNamespace = tok->str() == "namespace"; info.isNamespace = tok->str() == "namespace";
tok = tok->next();
info.className = tok->str(); info.className = tok->str();
tok = tok->next(); tok = tok->next();
while (tok && tok->str() != "{") while (tok && tok->str() != "{")
@ -9848,7 +9848,7 @@ void Tokenizer::removeUnnecessaryQualification()
else if (tok->str() == classInfo.back().className && else if (tok->str() == classInfo.back().className &&
Token::Match(tok, "%type% :: %type% (") && Token::Match(tok, "%type% :: %type% (") &&
Token::Match(tok->tokAt(3)->link(), ") const| {|;") && Token::Match(tok->tokAt(3)->link(), ") const| {|;") &&
tok->previous()->str() != ":") tok->previous()->str() != ":" && !classInfo.back().isNamespace)
{ {
std::string qualification = tok->str() + "::"; std::string qualification = tok->str() + "::";

View File

@ -354,6 +354,7 @@ private:
TEST_CASE(removeUnnecessaryQualification3); TEST_CASE(removeUnnecessaryQualification3);
TEST_CASE(removeUnnecessaryQualification4); TEST_CASE(removeUnnecessaryQualification4);
TEST_CASE(removeUnnecessaryQualification5); TEST_CASE(removeUnnecessaryQualification5);
TEST_CASE(removeUnnecessaryQualification6); // ticket #2859
TEST_CASE(simplifyIfNotNull); TEST_CASE(simplifyIfNotNull);
TEST_CASE(simplifyVarDecl1); // ticket # 2682 segmentation fault 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()); 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() void simplifyIfNotNull()
{ {
{ {