fix #2859 (Extra qualification not detected)
This commit is contained in:
parent
918b4d859f
commit
1713eeb532
|
@ -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() + "::";
|
||||
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue