Fixed #8600 (false-positive/regression: confusion between copy constructors of internal classes and lack of explicit keyword) (#1266)

This commit is contained in:
IOBYTE 2018-05-27 04:53:34 -04:00 committed by Daniel Marjamäki
parent 5b6e6db376
commit 36f7585798
3 changed files with 28 additions and 0 deletions

View File

@ -3790,6 +3790,10 @@ const Type* SymbolDatabase::findVariableType(const Scope *start, const Token *ty
// check if type does not have a namespace
if (typeTok->strAt(-1) != "::" && typeTok->strAt(1) != "::") {
// check if type same as scope
if (start->isClassOrStruct() && typeTok->str() == start->className)
return start->definedType;
while (scope) {
// look for type in this scope
const Type * type = scope->findType(typeTok->str());

View File

@ -413,6 +413,14 @@ private:
" return 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
// #8600
checkExplicitConstructors("struct A { struct B; };\n"
"struct A::B {\n"
" B() = default;\n"
" B(const B&) {}\n"
"};");
ASSERT_EQUALS("", errout.str());
}
void checkDuplInheritedMembers(const char code[]) {

View File

@ -289,6 +289,7 @@ private:
TEST_CASE(symboldatabase69);
TEST_CASE(symboldatabase70);
TEST_CASE(symboldatabase71);
TEST_CASE(symboldatabase72); // #8600
TEST_CASE(enum1);
TEST_CASE(enum2);
@ -3925,6 +3926,21 @@ private:
ASSERT(db && db->typeList.size() == 2);
}
void symboldatabase72() { // #8600
GET_SYMBOL_DB("struct A { struct B; };\n"
"struct A::B {\n"
" B() = default;\n"
" B(const B&) {}\n"
"};");
ASSERT(db && db->scopeList.size() == 4);
ASSERT(db && db->typeList.size() == 2);
const Token * f = db ? Token::findsimplematch(tokenizer.tokens(), "B ( const B & ) { }") : nullptr;
ASSERT(f != nullptr);
ASSERT(f && f->function() && f->function()->token->linenr() == 4);
ASSERT(f && f->function() && f->function()->type == Function::eCopyConstructor);
}
void enum1() {
GET_SYMBOL_DB("enum BOOL { FALSE, TRUE }; enum BOOL b;");