Don't suggest const for smartptr::get() (#5126)
* Don't suggest const for smartptr::get() * Fix test * Fix merge * get() doesn't change a smartpointer * Parentheses
This commit is contained in:
parent
12fe652321
commit
ec4267a2bd
|
@ -8586,7 +8586,6 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
|
|||
<use-retval/>
|
||||
<leak-ignore/>
|
||||
<noreturn>false</noreturn>
|
||||
<const/>
|
||||
<returnValue type="void *"/>
|
||||
</function>
|
||||
<function name="std::auto_ptr::reset,std::shared_ptr::reset,std::unique_ptr::reset,std::weak_ptr::reset">
|
||||
|
|
|
@ -2531,7 +2531,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings,
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (settings && settings->library.isFunctionConst(ftok))
|
||||
if ((settings && settings->library.isFunctionConst(ftok)) || (astIsSmartPointer(tok) && ftok->str() == "get")) // TODO: replace with action/yield?
|
||||
return false;
|
||||
|
||||
const Function * fun = ftok->function();
|
||||
|
|
|
@ -4724,6 +4724,14 @@ void smartPtr_get()
|
|||
*p = 1;
|
||||
}
|
||||
|
||||
void smartPtr_get2(std::vector<std::unique_ptr<int>>& v)
|
||||
{
|
||||
for (auto& u : v) {
|
||||
int* p = u.get();
|
||||
*p = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void smartPtr_reset()
|
||||
{
|
||||
std::unique_ptr<int> p(new int());
|
||||
|
|
|
@ -6532,7 +6532,7 @@ private:
|
|||
errout.str());
|
||||
|
||||
checkConst("struct S {\n"
|
||||
" bool f() { return p.get() != nullptr; }\n"
|
||||
" bool f() { return p != nullptr; }\n"
|
||||
" std::shared_ptr<int> p;\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Technically the member function 'S::f' can be const.\n",
|
||||
|
|
Loading…
Reference in New Issue