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

View File

@ -33,17 +33,18 @@ namespace {
namespace {
const std::set<std::string> _nonReentrantFunctions = make_container< std::set<std::string> > ()
<< "localtime" << "gmtime" << "strtok" << "gethostbyname" << "gethostbyaddr" << "getservbyname"
<< "getservbyport" << "crypt" << "ttyname" << "gethostbyname2"
<< "getprotobyname" << "getnetbyname" << "getnetbyaddr" << "getrpcbyname" << "getrpcbynumber" << "getrpcent"
<< "ctermid" << "readdir" << "getlogin" << "getpwent" << "getpwnam" << "getpwuid" << "getspent"
<< "fgetspent" << "getspnam" << "getgrnam" << "getgrgid" << "getnetgrent" << "tempnam" << "fgetpwent"
<< "fgetgrent" << "ecvt" << "gcvt" << "getservent" << "gethostent" << "getgrent" << "fcvt" ;
<< "localtime" << "gmtime" << "strtok" << "gethostbyname" << "gethostbyaddr" << "getservbyname"
<< "getservbyport" << "crypt" << "ttyname" << "gethostbyname2"
<< "getprotobyname" << "getnetbyname" << "getnetbyaddr" << "getrpcbyname" << "getrpcbynumber" << "getrpcent"
<< "ctermid" << "readdir" << "getlogin" << "getpwent" << "getpwnam" << "getpwuid" << "getspent"
<< "fgetspent" << "getspnam" << "getgrnam" << "getgrgid" << "getnetgrent" << "tempnam" << "fgetpwent"
<< "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. " +
"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()
@ -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);
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::set<std::string>::const_iterator it(_nonReentrantFunctions.begin()), itend(_nonReentrantFunctions.end());
for (; it!=itend; ++it) {

View File

@ -55,7 +55,7 @@ public:
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;

View File

@ -918,7 +918,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
// skip nothrow
if (_tokenizer->isCPP() && (Token::simpleMatch(type, "( nothrow )") ||
Token::simpleMatch(type, "( std :: nothrow )")))
Token::simpleMatch(type, "( std :: nothrow )")))
type = type->link()->next();
// 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) {
// finish filling in base class info
for (unsigned int i = 0; i < it->derivedFrom.size(); ++i) {
const Type* found = findType(it->derivedFrom[i].nameTok, it->enclosingScope);
if (found && found->findDependency(&(*it))) {
// circular dependency
//_tokenizer->syntaxError(nullptr);
}
else {
it->derivedFrom[i].type = found;
}
}
const Type* found = findType(it->derivedFrom[i].nameTok, it->enclosingScope);
if (found && found->findDependency(&(*it))) {
// circular dependency
//_tokenizer->syntaxError(nullptr);
} else {
it->derivedFrom[i].type = found;
}
}
}
// fill in friend info
@ -2062,14 +2061,15 @@ bool Type::hasCircularDependencies(std::set<BaseInfo>* anchestors) const
return false;
}
bool Type::findDependency(const Type* anchestor) const {
if (this==anchestor)
return true;
for (std::vector<BaseInfo>::const_iterator parent=derivedFrom.begin(); parent!=derivedFrom.end(); ++parent) {
if (parent->type && parent->type->findDependency(anchestor))
return true;
}
return false;
bool Type::findDependency(const Type* anchestor) const
{
if (this==anchestor)
return true;
for (std::vector<BaseInfo>::const_iterator parent=derivedFrom.begin(); parent!=derivedFrom.end(); ++parent) {
if (parent->type && parent->type->findDependency(anchestor))
return true;
}
return false;
}
bool Variable::arrayDimensions(const Library* lib)

View File

@ -124,12 +124,12 @@ public:
*/
bool hasCircularDependencies(std::set<BaseInfo>* anchestors = nullptr) const;
/**
/**
* Check for dependency
* @param anchestor potential anchestor
* @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. */

View File

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

View File

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

View File

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

View File

@ -6034,7 +6034,7 @@ private:
" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\n"
"}\n");
#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
ASSERT_EQUALS("", errout.str());
#endif

View File

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