diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 372aca40c..b07df25af 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10990,7 +10990,7 @@ void Tokenizer::removeUnnecessaryQualification() classInfo.pop_back(); else if (tok->str() == classInfo.back().className && !classInfo.back().isNamespace && tok->previous()->str() != ":" && - (Token::Match(tok, "%type% :: %type% (") || + (Token::Match(tok, "%type% :: ~| %type% (") || Token::Match(tok, "%type% :: operator"))) { int offset = 3; @@ -11011,6 +11011,8 @@ void Tokenizer::removeUnnecessaryQualification() offset++; } } + else if (tok->strAt(2) == "~") + offset++; if (Token::Match(tok->tokAt(offset)->link(), ") const| {|;|:")) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 0241c106e..4e4d0a0ec 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -372,6 +372,7 @@ private: TEST_CASE(removeUnnecessaryQualification6); // ticket #2859 TEST_CASE(removeUnnecessaryQualification7); // ticket #2970 TEST_CASE(removeUnnecessaryQualification8); + TEST_CASE(removeUnnecessaryQualification9); // ticket #3151 TEST_CASE(simplifyIfNotNull); TEST_CASE(simplifyVarDecl1); // ticket # 2682 segmentation fault @@ -7361,6 +7362,16 @@ private: "[test.cpp:5]: (portability) Extra qualification 'Fred::' unnecessary and considered an error by many compilers.\n", errout.str()); } + void removeUnnecessaryQualification9() + { + const char code[] = "class Fred {\n" + "public:\n" + " Fred::~Fred();\n" + "};\n"; + tok(code, false); + ASSERT_EQUALS("[test.cpp:3]: (portability) Extra qualification 'Fred::' unnecessary and considered an error by many compilers.\n", errout.str()); + } + void simplifyIfNotNull() { {