Remove some code checking for invalid class hierarchy which got obsolete since 480a5672b0. Run astyle

This commit is contained in:
Alexander Mai 2015-07-01 07:50:13 +02:00
parent 480a5672b0
commit 6e03e7dca2
11 changed files with 71 additions and 70 deletions

View File

@ -1764,7 +1764,7 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const
} }
// not found in this class // not found in this class
if (!scope->definedType->derivedFrom.empty() && !scope->definedType->hasCircularDependencies()) { if (!scope->definedType->derivedFrom.empty()) {
// check each base class // check each base class
for (std::size_t i = 0; i < scope->definedType->derivedFrom.size(); ++i) { for (std::size_t i = 0; i < scope->definedType->derivedFrom.size(); ++i) {
// find the base class // find the base class
@ -1794,7 +1794,7 @@ bool CheckClass::isMemberFunc(const Scope *scope, const Token *tok) const
const Type *derivedFrom = scope->definedType->derivedFrom[i].type; const Type *derivedFrom = scope->definedType->derivedFrom[i].type;
// find the function in the base class // find the function in the base class
if (derivedFrom && derivedFrom->classScope && !derivedFrom->hasCircularDependencies()) { if (derivedFrom && derivedFrom->classScope) {
if (isMemberFunc(derivedFrom->classScope, tok)) if (isMemberFunc(derivedFrom->classScope, tok))
return true; return true;
} }
@ -1817,7 +1817,7 @@ bool CheckClass::isConstMemberFunc(const Scope *scope, const Token *tok) const
const Type *derivedFrom = scope->definedType->derivedFrom[i].type; const Type *derivedFrom = scope->definedType->derivedFrom[i].type;
// find the function in the base class // find the function in the base class
if (derivedFrom && derivedFrom->classScope && !derivedFrom->hasCircularDependencies()) { if (derivedFrom && derivedFrom->classScope) {
if (isConstMemberFunc(derivedFrom->classScope, tok)) if (isConstMemberFunc(derivedFrom->classScope, tok))
return true; return true;
} }

View File

@ -33,17 +33,18 @@ namespace {
namespace { namespace {
const std::set<std::string> _nonReentrantFunctions = make_container< std::set<std::string> > () const std::set<std::string> _nonReentrantFunctions = make_container< std::set<std::string> > ()
<< "localtime" << "gmtime" << "strtok" << "gethostbyname" << "gethostbyaddr" << "getservbyname" << "localtime" << "gmtime" << "strtok" << "gethostbyname" << "gethostbyaddr" << "getservbyname"
<< "getservbyport" << "crypt" << "ttyname" << "gethostbyname2" << "getservbyport" << "crypt" << "ttyname" << "gethostbyname2"
<< "getprotobyname" << "getnetbyname" << "getnetbyaddr" << "getrpcbyname" << "getrpcbynumber" << "getrpcent" << "getprotobyname" << "getnetbyname" << "getnetbyaddr" << "getrpcbyname" << "getrpcbynumber" << "getrpcent"
<< "ctermid" << "readdir" << "getlogin" << "getpwent" << "getpwnam" << "getpwuid" << "getspent" << "ctermid" << "readdir" << "getlogin" << "getpwent" << "getpwnam" << "getpwuid" << "getspent"
<< "fgetspent" << "getspnam" << "getgrnam" << "getgrgid" << "getnetgrent" << "tempnam" << "fgetpwent" << "fgetspent" << "getspnam" << "getgrnam" << "getgrgid" << "getnetgrent" << "tempnam" << "fgetpwent"
<< "fgetgrent" << "ecvt" << "gcvt" << "getservent" << "gethostent" << "getgrent" << "fcvt" ; << "fgetgrent" << "ecvt" << "gcvt" << "getservent" << "gethostent" << "getgrent" << "fcvt" ;
} }
std::string CheckNonReentrantFunctions::generateErrorMessage(const std::string& function) { std::string CheckNonReentrantFunctions::generateErrorMessage(const std::string& function)
{
return std::string("Non reentrant function '") + function + "' called. " + return std::string("Non reentrant function '") + function + "' called. " +
"For threadsafe applications it is recommended to use the reentrant replacement function '" + function + "_r'."; "For threadsafe applications it is recommended to use the reentrant replacement function '" + function + "_r'.";
} }
void CheckNonReentrantFunctions::nonReentrantFunctions() void CheckNonReentrantFunctions::nonReentrantFunctions()
@ -83,7 +84,8 @@ void CheckNonReentrantFunctions::nonReentrantFunctions()
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckNonReentrantFunctions::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { void CheckNonReentrantFunctions::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const
{
CheckNonReentrantFunctions c(0, settings, errorLogger); CheckNonReentrantFunctions c(0, settings, errorLogger);
std::set<std::string>::const_iterator it(_nonReentrantFunctions.begin()), itend(_nonReentrantFunctions.end()); std::set<std::string>::const_iterator it(_nonReentrantFunctions.begin()), itend(_nonReentrantFunctions.end());
@ -92,7 +94,8 @@ void CheckNonReentrantFunctions::getErrorMessages(ErrorLogger *errorLogger, cons
} }
} }
std::string CheckNonReentrantFunctions::classInfo() const { std::string CheckNonReentrantFunctions::classInfo() const
{
std::string info = "Warn if any of these non reentrant functions are used:\n"; std::string info = "Warn if any of these non reentrant functions are used:\n";
std::set<std::string>::const_iterator it(_nonReentrantFunctions.begin()), itend(_nonReentrantFunctions.end()); std::set<std::string>::const_iterator it(_nonReentrantFunctions.begin()), itend(_nonReentrantFunctions.end());
for (; it!=itend; ++it) { for (; it!=itend; ++it) {

View File

@ -55,7 +55,7 @@ public:
private: private:
static std::string generateErrorMessage(const std::string& function); static std::string generateErrorMessage(const std::string& function);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const; void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const;

View File

@ -918,7 +918,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
// skip nothrow // skip nothrow
if (_tokenizer->isCPP() && (Token::simpleMatch(type, "( nothrow )") || if (_tokenizer->isCPP() && (Token::simpleMatch(type, "( nothrow )") ||
Token::simpleMatch(type, "( std :: nothrow )"))) Token::simpleMatch(type, "( std :: nothrow )")))
type = type->link()->next(); type = type->link()->next();
// is it a user defined type? // is it a user defined type?

View File

@ -845,15 +845,14 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
for (std::list<Type>::iterator it = typeList.begin(); it != typeList.end(); ++it) { for (std::list<Type>::iterator it = typeList.begin(); it != typeList.end(); ++it) {
// finish filling in base class info // finish filling in base class info
for (unsigned int i = 0; i < it->derivedFrom.size(); ++i) { for (unsigned int i = 0; i < it->derivedFrom.size(); ++i) {
const Type* found = findType(it->derivedFrom[i].nameTok, it->enclosingScope); const Type* found = findType(it->derivedFrom[i].nameTok, it->enclosingScope);
if (found && found->findDependency(&(*it))) { if (found && found->findDependency(&(*it))) {
// circular dependency // circular dependency
//_tokenizer->syntaxError(nullptr); //_tokenizer->syntaxError(nullptr);
} } else {
else { it->derivedFrom[i].type = found;
it->derivedFrom[i].type = found; }
} }
}
} }
// fill in friend info // fill in friend info
@ -2062,14 +2061,15 @@ bool Type::hasCircularDependencies(std::set<BaseInfo>* anchestors) const
return false; return false;
} }
bool Type::findDependency(const Type* anchestor) const { bool Type::findDependency(const Type* anchestor) const
if (this==anchestor) {
return true; if (this==anchestor)
for (std::vector<BaseInfo>::const_iterator parent=derivedFrom.begin(); parent!=derivedFrom.end(); ++parent) { return true;
if (parent->type && parent->type->findDependency(anchestor)) for (std::vector<BaseInfo>::const_iterator parent=derivedFrom.begin(); parent!=derivedFrom.end(); ++parent) {
return true; if (parent->type && parent->type->findDependency(anchestor))
} return true;
return false; }
return false;
} }
bool Variable::arrayDimensions(const Library* lib) bool Variable::arrayDimensions(const Library* lib)

View File

@ -124,12 +124,12 @@ public:
*/ */
bool hasCircularDependencies(std::set<BaseInfo>* anchestors = nullptr) const; bool hasCircularDependencies(std::set<BaseInfo>* anchestors = nullptr) const;
/** /**
* Check for dependency * Check for dependency
* @param anchestor potential anchestor * @param anchestor potential anchestor
* @return true if there is a dependency * @return true if there is a dependency
*/ */
bool findDependency(const Type* anchestor) const; bool findDependency(const Type* anchestor) const;
}; };
/** @brief Information about a member variable. */ /** @brief Information about a member variable. */

View File

@ -824,8 +824,7 @@ const Token * Token::findClosingBracket() const
closing = closing->link(); closing = closing->link();
if (!closing) if (!closing)
return nullptr; // #6803 return nullptr; // #6803
} } else if (Token::Match(closing, "}|]|)|;"))
else if (Token::Match(closing, "}|]|)|;"))
break; break;
else if (closing->str() == "<") else if (closing->str() == "<")
++depth; ++depth;
@ -1436,8 +1435,8 @@ const Token *Token::getValueTokenDeadPointer() const
const Variable * const var = vartok->variable(); const Variable * const var = vartok->variable();
if (var->isStatic() || var->isReference()) if (var->isStatic() || var->isReference())
continue; continue;
if (!var->scope()) if (!var->scope())
return nullptr; // #6804 return nullptr; // #6804
if (var->scope()->type == Scope::eUnion && var->scope()->nestedIn == this->scope()) if (var->scope()->type == Scope::eUnion && var->scope()->nestedIn == this->scope())
continue; continue;
// variable must be in same function (not in subfunction) // variable must be in same function (not in subfunction)

View File

@ -1455,7 +1455,7 @@ private:
" ;\n" " ;\n"
"}"); "}");
#ifdef _MSC_VER #ifdef _MSC_VER
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
#else #else
TODO_ASSERT_EQUALS("", "[test.cpp:2]: (style) Redundant condition: If init == 9894494448401390090, the comparison init == 9965707617509186058 is always true.\n", errout.str()); TODO_ASSERT_EQUALS("", "[test.cpp:2]: (style) Redundant condition: If init == 9894494448401390090, the comparison init == 9965707617509186058 is always true.\n", errout.str());
#endif #endif

View File

@ -134,7 +134,7 @@ private:
TEST_CASE(garbageCode92); TEST_CASE(garbageCode92);
TEST_CASE(garbageCode93); TEST_CASE(garbageCode93);
TEST_CASE(garbageCode94); TEST_CASE(garbageCode94);
TEST_CASE(garbageCode95); TEST_CASE(garbageCode95);
TEST_CASE(garbageValueFlow); TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase); TEST_CASE(garbageSymbolDatabase);
@ -142,18 +142,17 @@ private:
TEST_CASE(templateSimplifierCrashes); TEST_CASE(templateSimplifierCrashes);
} }
std::string checkCode(const char code[], const std::string& filename = "test.cpp") { std::string checkCode(const char code[], const std::string& filename = "test.cpp") {
// double the tests - run each example as C as well as C++ // double the tests - run each example as C as well as C++
const std::string alternatefilename = (filename=="test.c") ? "test.cpp" : "test.c"; const std::string alternatefilename = (filename=="test.c") ? "test.cpp" : "test.c";
// run alternate check first. It should only ensure stability // run alternate check first. It should only ensure stability
try { try {
checkCodeInternal(code, alternatefilename); checkCodeInternal(code, alternatefilename);
} } catch (InternalError&) {
catch(InternalError& ) { }
}
return checkCodeInternal(code, filename); return checkCodeInternal(code, filename);
} }
std::string checkCodeInternal(const char code[], const std::string& filename) { std::string checkCodeInternal(const char code[], const std::string& filename) {
errout.str(""); errout.str("");
@ -170,7 +169,7 @@ private:
// tokenize.. // tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, filename.c_str()); tokenizer.tokenize(istr, filename.c_str());
// call all "runChecks" in all registered Check classes // call all "runChecks" in all registered Check classes
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) { for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
@ -749,7 +748,7 @@ private:
} }
void garbageCode95() { // #6804 void garbageCode95() { // #6804
checkCode("{ } x x ; { } h h [ ] ( ) ( ) { struct x ( x ) ; int __attribute__ ( ) f ( ) { h - > first = & x ; struct x * n = h - > first ; ( ) n > } }"); // do not crash checkCode("{ } x x ; { } h h [ ] ( ) ( ) { struct x ( x ) ; int __attribute__ ( ) f ( ) { h - > first = & x ; struct x * n = h - > first ; ( ) n > } }"); // do not crash
} }
void garbageValueFlow() { void garbageValueFlow() {

View File

@ -6034,7 +6034,7 @@ private:
" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\n" " if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\n"
"}\n"); "}\n");
#ifdef _MSC_VER #ifdef _MSC_VER
TODO_ASSERT_EQUALS("", "[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout.str()); TODO_ASSERT_EQUALS("", "[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout.str());
#else #else
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
#endif #endif

View File

@ -260,7 +260,7 @@ private:
TEST_CASE(functionPrototype); // ticket #5867 TEST_CASE(functionPrototype); // ticket #5867
TEST_CASE(lambda); // ticket #5867 TEST_CASE(lambda); // ticket #5867
TEST_CASE(circularDependencies); // 6298 TEST_CASE(circularDependencies); // 6298
} }
void array() const { void array() const {
@ -2915,21 +2915,21 @@ private:
ASSERT_EQUALS(Scope::eLambda, scope->type); ASSERT_EQUALS(Scope::eLambda, scope->type);
} }
} }
// #6298 "stack overflow in Scope::findFunctionInBase (endless recursion)" // #6298 "stack overflow in Scope::findFunctionInBase (endless recursion)"
void circularDependencies() { void circularDependencies() {
check("template<template<class> class E,class D> class C : E<D> {\n" check("template<template<class> class E,class D> class C : E<D> {\n"
" public:\n" " public:\n"
" int f();\n" " int f();\n"
"};\n" "};\n"
"class E : C<D,int> {\n" "class E : C<D,int> {\n"
" public:\n" " public:\n"
" int f() { return C< ::D,int>::f(); }\n" " int f() { return C< ::D,int>::f(); }\n"
"};\n" "};\n"
"int main() {\n" "int main() {\n"
" E c;\n" " E c;\n"
" c.f();\n" " c.f();\n"
"}"); "}");
} }
}; };
REGISTER_TEST(TestSymbolDatabase) REGISTER_TEST(TestSymbolDatabase)