This commit is contained in:
parent
cb382ac52c
commit
ecb24e28bc
|
@ -2742,7 +2742,7 @@ void CheckOther::checkRedundantCopy()
|
|||
const Token* startTok = var->nameToken();
|
||||
if (startTok->strAt(1) == "=") // %type% %name% = ... ;
|
||||
;
|
||||
else if (startTok->strAt(1) == "(" && var->isClass() && var->typeScope()) {
|
||||
else if (Token::Match(startTok->next(), "(|{") && var->isClass() && var->typeScope()) {
|
||||
// Object is instantiated. Warn if constructor takes arguments by value.
|
||||
if (constructorTakesReference(var->typeScope()))
|
||||
continue;
|
||||
|
@ -2760,6 +2760,8 @@ void CheckOther::checkRedundantCopy()
|
|||
const Token* dot = tok->astOperand1();
|
||||
if (Token::simpleMatch(dot, ".") && dot->astOperand1() && isVariableChanged(dot->astOperand1()->variable(), mSettings, mTokenizer->isCPP()))
|
||||
continue;
|
||||
if (exprDependsOnThis(tok->previous()))
|
||||
continue;
|
||||
|
||||
const Function* func = tok->previous()->function();
|
||||
if (func && func->tokenDef->strAt(-1) == "&") {
|
||||
|
|
|
@ -7509,6 +7509,14 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("class A {};\n"
|
||||
"class B { B(const A& a); };\n"
|
||||
"const A& getA();\n"
|
||||
"void f() {\n"
|
||||
" const B b{ getA() };\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #5618
|
||||
const char* code5618 = "class Token {\n"
|
||||
"public:\n"
|
||||
|
@ -7557,6 +7565,24 @@ private:
|
|||
" return {};\n"
|
||||
"}", nullptr, /*experimental*/ false, /*inconclusive*/ true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("struct X { int x; };\n" // #10191
|
||||
"struct S {\n"
|
||||
" X _x;\n"
|
||||
" X& get() { return _x; }\n"
|
||||
" void modify() { _x.x += 42; }\n"
|
||||
" int copy() {\n"
|
||||
" const X x = get();\n"
|
||||
" modify();\n"
|
||||
" return x.x;\n"
|
||||
" }\n"
|
||||
" int constref() {\n"
|
||||
" const X& x = get();\n"
|
||||
" modify();\n"
|
||||
" return x.x;\n"
|
||||
" }\n"
|
||||
"};\n", nullptr, /*experimental*/ false, /*inconclusive*/ true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void checkNegativeShift() {
|
||||
|
|
Loading…
Reference in New Issue