#7062 Remove unnecessaryQualification check
This commit is contained in:
parent
9be284e80f
commit
8667184f12
|
@ -8656,7 +8656,6 @@ void Tokenizer::getErrorMessages(ErrorLogger *errorLogger, const Settings *setti
|
|||
t.duplicateTypedefError(0, 0, "variable");
|
||||
t.duplicateDeclarationError(0, 0, "variable");
|
||||
t.duplicateEnumError(0, 0, "variable");
|
||||
t.unnecessaryQualificationError(0, "type");
|
||||
}
|
||||
|
||||
void Tokenizer::simplifyWhile0()
|
||||
|
@ -9875,30 +9874,6 @@ void Tokenizer::removeUnnecessaryQualification()
|
|||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::string qualification;
|
||||
if (portabilityEnabled)
|
||||
qualification = tok->str() + "::";
|
||||
|
||||
// check for extra qualification
|
||||
/** @todo this should be made more generic to handle more levels */
|
||||
if (Token::Match(tok->tokAt(-2), "%type% ::")) {
|
||||
if (classInfo.size() >= 2) {
|
||||
if (classInfo[classInfo.size() - 2].className != tok->strAt(-2))
|
||||
continue;
|
||||
if (portabilityEnabled)
|
||||
qualification = tok->strAt(-2) + "::" + qualification;
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
|
||||
if (portabilityEnabled)
|
||||
unnecessaryQualificationError(tok, qualification);
|
||||
|
||||
tok->deleteNext();
|
||||
tok->deleteThis();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9917,12 +9892,6 @@ void Tokenizer::simplifyDeprecated()
|
|||
}
|
||||
}
|
||||
|
||||
void Tokenizer::unnecessaryQualificationError(const Token *tok, const std::string &qualification) const
|
||||
{
|
||||
reportError(tok, Severity::portability, "unnecessaryQualification",
|
||||
"The extra qualification \'" + qualification + "\' is unnecessary and is considered an error by many compilers.");
|
||||
}
|
||||
|
||||
void Tokenizer::simplifyReturnStrncat()
|
||||
{
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
|
|
|
@ -638,11 +638,6 @@ private:
|
|||
*/
|
||||
void removeUnnecessaryQualification();
|
||||
|
||||
/**
|
||||
* unnecessary member qualification error
|
||||
*/
|
||||
void unnecessaryQualificationError(const Token *tok, const std::string &qualification) const;
|
||||
|
||||
/**
|
||||
* Add std:: in front of std classes, when using namespace std; was given
|
||||
*/
|
||||
|
|
|
@ -14,7 +14,7 @@ CPPCHECK_OPT='--check-library --enable=information --enable=style --error-exitco
|
|||
|
||||
# Compiler settings
|
||||
CXX=g++
|
||||
CXX_OPT='-fsyntax-only -std=c++0x -Wno-format -Wno-format-security -Wno-nonnull '
|
||||
CXX_OPT='-fsyntax-only -std=c++0x -Wno-format -Wno-format-security'
|
||||
CC=gcc
|
||||
CC_OPT='-Wno-format -Wno-nonnull -Wno-implicit-function-declaration -Wno-deprecated-declarations -Wno-format-security -Wno-nonnull -fsyntax-only'
|
||||
|
||||
|
|
|
@ -768,20 +768,20 @@ private:
|
|||
|
||||
void suppressionTwo() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppress=uninitvar,unnecessaryQualification", "file.cpp"};
|
||||
const char *argv[] = {"cppcheck", "--suppress=uninitvar,noConstructor", "file.cpp"};
|
||||
settings = Settings();
|
||||
TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv));
|
||||
TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U));
|
||||
TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed("unnecessaryQualification", "file.cpp", 1U));
|
||||
TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed("noConstructor", "file.cpp", 1U));
|
||||
}
|
||||
|
||||
void suppressionTwoSeparate() {
|
||||
REDIRECT;
|
||||
const char *argv[] = {"cppcheck", "--suppress=uninitvar", "--suppress=unnecessaryQualification", "file.cpp"};
|
||||
const char *argv[] = {"cppcheck", "--suppress=uninitvar", "--suppress=noConstructor", "file.cpp"};
|
||||
settings = Settings();
|
||||
ASSERT(defParser.ParseFromArgs(4, argv));
|
||||
ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U));
|
||||
ASSERT_EQUALS(true, settings.nomsg.isSuppressed("unnecessaryQualification", "file.cpp", 1U));
|
||||
ASSERT_EQUALS(true, settings.nomsg.isSuppressed("noConstructor", "file.cpp", 1U));
|
||||
}
|
||||
|
||||
void templates() {
|
||||
|
|
|
@ -247,24 +247,6 @@ private:
|
|||
// void foo(void) -> void foo()
|
||||
TEST_CASE(removeVoidFromFunction);
|
||||
|
||||
TEST_CASE(removeUnnecessaryQualification1);
|
||||
TEST_CASE(removeUnnecessaryQualification2);
|
||||
TEST_CASE(removeUnnecessaryQualification3);
|
||||
TEST_CASE(removeUnnecessaryQualification4);
|
||||
TEST_CASE(removeUnnecessaryQualification5);
|
||||
TEST_CASE(removeUnnecessaryQualification6); // ticket #2859
|
||||
TEST_CASE(removeUnnecessaryQualification7); // ticket #2970
|
||||
TEST_CASE(removeUnnecessaryQualification8);
|
||||
TEST_CASE(removeUnnecessaryQualification9); // ticket #3151
|
||||
TEST_CASE(removeUnnecessaryQualification10); // ticket #3310 segmentation fault
|
||||
TEST_CASE(removeUnnecessaryQualification11);
|
||||
TEST_CASE(removeUnnecessaryQualification12);
|
||||
TEST_CASE(removeUnnecessaryQualification13);
|
||||
TEST_CASE(removeUnnecessaryQualification14);
|
||||
TEST_CASE(removeUnnecessaryQualification15);
|
||||
TEST_CASE(removeUnnecessaryQualification16);
|
||||
TEST_CASE(removeUnnecessaryQualification17);
|
||||
|
||||
TEST_CASE(simplifyVarDecl1); // ticket # 2682 segmentation fault
|
||||
TEST_CASE(simplifyVarDecl2); // ticket # 2834 segmentation fault
|
||||
TEST_CASE(return_strncat); // ticket # 2860 Returning value of strncat() reported as memory leak
|
||||
|
@ -3920,206 +3902,6 @@ private:
|
|||
ASSERT_EQUALS("void foo ( ) ;", tok("void foo(void);"));
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification1() {
|
||||
const char code[] = "class Fred { Fred::Fred() {} };";
|
||||
const char expected[] = "class Fred { Fred ( ) { } } ;";
|
||||
ASSERT_EQUALS(expected, tok(code, false));
|
||||
ASSERT_EQUALS("[test.cpp:1]: (portability) The extra qualification 'Fred::' is unnecessary and is considered an error by many compilers.\n", errout.str());
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification2() {
|
||||
const char code[] = "template<typename Iter, typename Skip>\n"
|
||||
"struct grammar : qi::grammar<Iter, int(), Skip> {\n"
|
||||
" grammar() : grammar::base_type(start) { }\n"
|
||||
"};\n";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification3() {
|
||||
const char code[] = "namespace one {\n"
|
||||
" class c {\n"
|
||||
" public:\n"
|
||||
" void function() {}\n"
|
||||
" };\n"
|
||||
"}\n"
|
||||
"namespace two {\n"
|
||||
" class c : public one::c {\n"
|
||||
" public:\n"
|
||||
" void function() {\n"
|
||||
" one::c::function();\n"
|
||||
" }\n"
|
||||
" };\n"
|
||||
"}\n";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification4() {
|
||||
const char code[] = "namespace one {\n"
|
||||
" class c {\n"
|
||||
" public:\n"
|
||||
" void function() {}\n"
|
||||
" };\n"
|
||||
"}\n"
|
||||
"class c : public one::c {\n"
|
||||
"public:\n"
|
||||
" void function() {\n"
|
||||
" one::c::function();\n"
|
||||
" }\n"
|
||||
"};\n";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification5() {
|
||||
const char code[] = "namespace one {\n"
|
||||
" class c {\n"
|
||||
" public:\n"
|
||||
" void function() {}\n"
|
||||
" };\n"
|
||||
"}\n"
|
||||
"namespace two {\n"
|
||||
" class c : public one::c {\n"
|
||||
" public:\n"
|
||||
" void function() {\n"
|
||||
" two::c::function();\n"
|
||||
" }\n"
|
||||
" };\n"
|
||||
"}\n";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("", 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 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) The extra qualification 'TProcedure::' is unnecessary and is considered an error by many compilers.\n", errout.str());
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification8() {
|
||||
const char code[] = "class Fred {\n"
|
||||
"public:\n"
|
||||
" Fred & Fred::operator = (const Fred &);\n"
|
||||
" void Fred::operator () (void);\n"
|
||||
" void Fred::operator delete[](void* x);\n"
|
||||
"};\n";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (portability) The extra qualification 'Fred::' is unnecessary and is considered an error by many compilers.\n"
|
||||
"[test.cpp:4]: (portability) The extra qualification 'Fred::' is unnecessary and is considered an error by many compilers.\n"
|
||||
"[test.cpp:5]: (portability) The extra qualification 'Fred::' is unnecessary and is 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) The extra qualification 'Fred::' is unnecessary and is considered an error by many compilers.\n", errout.str());
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification10() {
|
||||
const char code[] = "template<typename T> class A\n"
|
||||
"{\n"
|
||||
" operator T();\n"
|
||||
" A() { T (A::*f)() = &A::operator T; }\n"
|
||||
"};\n";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification11() {
|
||||
const char code[] = "class Fred {\n"
|
||||
"public:\n"
|
||||
" Fred& Fred::Magic();\n"
|
||||
"};\n";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (portability) The extra qualification 'Fred::' is unnecessary and is considered an error by many compilers.\n", errout.str());
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification12() {
|
||||
const char code[] = "class Fred {\n"
|
||||
"public:\n"
|
||||
" Fred* Fred::Magic();\n"
|
||||
"};\n";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (portability) The extra qualification 'Fred::' is unnecessary and is considered an error by many compilers.\n", errout.str());
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification13() {
|
||||
const char code[] = "class Fred {\n"
|
||||
"public:\n"
|
||||
" Fred** Fred::Magic();\n"
|
||||
"};\n";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (portability) The extra qualification 'Fred::' is unnecessary and is considered an error by many compilers.\n", errout.str());
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification14() {
|
||||
const char code[] = "class Fred {\n"
|
||||
"public:\n"
|
||||
" Fred*& Fred::Magic();\n"
|
||||
"};\n";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (portability) The extra qualification 'Fred::' is unnecessary and is considered an error by many compilers.\n", errout.str());
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification15() {
|
||||
const char code[] = "class Fred {\n"
|
||||
"public:\n"
|
||||
" Fred*& Magic() {\n"
|
||||
" Fred::Magic(param);\n"
|
||||
" }\n"
|
||||
"};\n";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification16() {
|
||||
const char code[] = "class Fred {\n"
|
||||
"public:\n"
|
||||
" void Fred::Magic();\n"
|
||||
"};\n";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (portability) The extra qualification 'Fred::' is unnecessary and is considered an error by many compilers.\n", errout.str());
|
||||
}
|
||||
|
||||
void removeUnnecessaryQualification17() { // #6628 False positive: The extra qualification 'namespace::' is unnecessary and is considered an error by many compilers.
|
||||
const char code[] = "namespace my_application {\n"
|
||||
" std::string version();\n"
|
||||
"}\n"
|
||||
"namespace my_application_test {\n"
|
||||
" class my_application {\n"
|
||||
" void version() {\n"
|
||||
" std::string version = ::my_application::version();\n"
|
||||
" }\n"
|
||||
" };\n"
|
||||
"}";
|
||||
tok(code, false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void simplifyVarDecl1() { // ticket # 2682 segmentation fault
|
||||
const char code[] = "x a[0] =";
|
||||
tok(code, false);
|
||||
|
|
Loading…
Reference in New Issue