diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 64aafd93b..0ab309cbd 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -422,7 +422,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti } // find the return type - if (function.type != Function::eConstructor) { + if (!function.isConstructor() && !function.isDestructor()) { while (tok1 && Token::Match(tok1->next(), "virtual|static|friend|const|struct|union")) tok1 = tok1->next(); @@ -1744,7 +1744,8 @@ void SymbolDatabase::printOut(const char *title) const std::cout << " retFuncPtr: " << (func->retFuncPtr ? "true" : "false") << std::endl; std::cout << " tokenDef: " << func->tokenDef->str() << " " <<_tokenizer->list.fileLine(func->tokenDef) << std::endl; std::cout << " argDef: " << _tokenizer->list.fileLine(func->argDef) << std::endl; - std::cout << " retDef: " << func->retDef->str() << " " <<_tokenizer->list.fileLine(func->retDef) << std::endl; + if (!func->isConstructor() && !func->isDestructor()) + std::cout << " retDef: " << func->retDef->str() << " " <<_tokenizer->list.fileLine(func->retDef) << std::endl; std::cout << " retType: " << func->retType << std::endl; if (func->hasBody) { std::cout << " token: " << _tokenizer->list.fileLine(func->token) << std::endl; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 94cfdd62f..3fb5e36ef 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -638,6 +638,7 @@ private: ASSERT(function && function->token == tokenizer.tokens()->next()); ASSERT(function && function->hasBody); ASSERT(function && function->functionScope == scope && scope->function == function && function->nestedIn != scope); + ASSERT(function && function->retDef == tokenizer.tokens()); } } @@ -659,6 +660,7 @@ private: ASSERT(function && function->token == tokenizer.tokens()->tokAt(4)); ASSERT(function && function->hasBody && function->isInline); ASSERT(function && function->functionScope == scope && scope->function == function && function->nestedIn == db->findScopeByName("Fred")); + ASSERT(function && function->retDef == tokenizer.tokens()->tokAt(3)); ASSERT(db && db->findScopeByName("Fred") && db->findScopeByName("Fred")->definedType->getFunction("func") == function); } @@ -803,21 +805,25 @@ private: GET_SYMBOL_DB("class Foo { Foo(Foo f); };"); const Function* ctor = tokenizer.tokens()->tokAt(3)->function(); ASSERT(db && ctor && ctor->type == Function::eConstructor && !ctor->isExplicit); + ASSERT(ctor && ctor->retDef == 0); } { GET_SYMBOL_DB("class Foo { explicit Foo(Foo f); };"); const Function* ctor = tokenizer.tokens()->tokAt(4)->function(); ASSERT(db && ctor && ctor->type == Function::eConstructor && ctor->isExplicit); + ASSERT(ctor && ctor->retDef == 0); } { GET_SYMBOL_DB("class Foo { Foo(Foo& f); };"); const Function* ctor = tokenizer.tokens()->tokAt(3)->function(); ASSERT(db && ctor && ctor->type == Function::eCopyConstructor); + ASSERT(ctor && ctor->retDef == 0); } { GET_SYMBOL_DB("class Foo { Foo(Foo&& f); };"); const Function* ctor = tokenizer.tokens()->tokAt(3)->function(); ASSERT(db && ctor && ctor->type == Function::eMoveConstructor); + ASSERT(ctor && ctor->retDef == 0); } }