parent
3cf67014ad
commit
b0bf69bae7
|
@ -815,18 +815,20 @@ void CheckClass::initializationListUsage()
|
||||||
break;
|
break;
|
||||||
if (Token::Match(tok, "try|do {"))
|
if (Token::Match(tok, "try|do {"))
|
||||||
break;
|
break;
|
||||||
if (Token::Match(tok, "%var% = %any%")) {
|
if (Token::Match(tok, "%var% = %any%") && tok->strAt(-1) != "*") {
|
||||||
const Variable* var = tok->variable();
|
const Variable* var = tok->variable();
|
||||||
if (var && var->scope() == owner && !var->isStatic()) {
|
if (var && var->scope() == owner && !var->isStatic()) {
|
||||||
|
if (var->isPointer() || var->isReference() || (!var->type() && !var->isStlStringType() && !(Token::Match(var->typeStartToken(), "std :: %type% <") && !Token::simpleMatch(var->typeStartToken()->linkAt(3), "> ::"))))
|
||||||
|
continue;
|
||||||
|
|
||||||
bool allowed = true;
|
bool allowed = true;
|
||||||
for (const Token* tok2 = tok->tokAt(2); tok2 && tok2->str() != ";"; tok2 = tok2->next()) {
|
for (const Token* tok2 = tok->tokAt(2); tok2 && tok2->str() != ";"; tok2 = tok2->next()) {
|
||||||
if (tok2->varId()) {
|
|
||||||
const Variable* var2 = tok2->variable();
|
const Variable* var2 = tok2->variable();
|
||||||
if (var2 && var2->scope() == owner &&
|
if (var2) {
|
||||||
tok2->strAt(-1)!=".") { // Is there a dependency between two member variables?
|
if (var2->scope() == owner && tok2->strAt(-1)!=".") { // Is there a dependency between two member variables?
|
||||||
allowed = false;
|
allowed = false;
|
||||||
break;
|
break;
|
||||||
} else if (var2 && (var2->isArray() && var2->isLocal())) { // Can't initialize with a local array
|
} else if (var2->isArray() && var2->isLocal()) { // Can't initialize with a local array
|
||||||
allowed = false;
|
allowed = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -840,7 +842,7 @@ void CheckClass::initializationListUsage()
|
||||||
}
|
}
|
||||||
if (!allowed)
|
if (!allowed)
|
||||||
continue;
|
continue;
|
||||||
if (!var->isPointer() && !var->isReference() && (var->type() || var->isStlStringType() || (Token::Match(var->typeStartToken(), "std :: %type% <") && !Token::simpleMatch(var->typeStartToken()->linkAt(3), "> ::"))))
|
|
||||||
suggestInitializationList(tok, tok->str());
|
suggestInitializationList(tok, tok->str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5958,6 +5958,14 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"};");
|
"};");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkInitializationListUsage("class B {\n" // #5640
|
||||||
|
" std::shared_ptr<A> _d;\n"
|
||||||
|
" B(const B& other) : _d(std::make_shared<A>()) {\n"
|
||||||
|
" *_d = *other._d;\n"
|
||||||
|
" }\n"
|
||||||
|
"};");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue