one definition rule: Fixed false positive for 'class A::B ..'

This commit is contained in:
Daniel Marjamäki 2021-04-04 21:29:45 +02:00
parent 084bc74080
commit a21c81365d
2 changed files with 8 additions and 0 deletions

View File

@ -2859,6 +2859,11 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti
std::string name;
const Scope *scope = classScope;
while (scope->isClassOrStruct() && !classScope->className.empty()) {
if (Token::Match(scope->classDef, "struct|class %name% :: %name%")) {
// TODO handle such classnames
name.clear();
break;
}
name = scope->className + "::" + name;
scope = scope->nestedIn;
}

View File

@ -7428,6 +7428,9 @@ private:
ctu({"class C { C(); }; C::C(){}", "class C { C(); }; C::C(){}"});
ASSERT_EQUALS("", errout.str());
ctu({"class A::C { C() { std::cout << 0; } };", "class B::C { C() { std::cout << 1; } };"});
ASSERT_EQUALS("", errout.str());
}
void getFileInfo(const char code[]) {