Fixed #1847 (False positive: Method using std::swap<>() can be declared const)
This commit is contained in:
parent
7d0fd3f2aa
commit
ab088bcec9
|
@ -1996,7 +1996,8 @@ bool CheckClass::checkConstFunc(const std::string &classname, const Var *varlist
|
|||
}
|
||||
|
||||
// function call..
|
||||
else if (tok1->str() != "return" && Token::Match(tok1, "%var% (") && tok1->str() != "c_str")
|
||||
else if ((tok1->str() != "return" && Token::Match(tok1, "%var% (") && tok1->str() != "c_str") ||
|
||||
Token::Match(tok1, "%var% < %any% > ("))
|
||||
{
|
||||
isconst = false;
|
||||
break;
|
||||
|
|
|
@ -126,6 +126,7 @@ private:
|
|||
TEST_CASE(const23); // ticket #1699
|
||||
TEST_CASE(const24); // ticket #1708
|
||||
TEST_CASE(const25); // ticket #1724
|
||||
TEST_CASE(const26); // ticket #1847
|
||||
TEST_CASE(constoperator1); // operator< can often be const
|
||||
TEST_CASE(constoperator2); // operator<<
|
||||
TEST_CASE(constincdec); // increment/decrement => non-const
|
||||
|
@ -3569,6 +3570,19 @@ private:
|
|||
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) The function 'A::strGetSize' can be const\n", errout.str());
|
||||
}
|
||||
|
||||
void const26() // ticket #1847
|
||||
{
|
||||
checkConst("class DelayBase {\n"
|
||||
"public:\n"
|
||||
"void swapSpecificDelays(int index1, int index2) {\n"
|
||||
" std::swap<float>(delays_[index1], delays_[index2]);\n"
|
||||
"}\n"
|
||||
"float delays_[4];\n"
|
||||
"};\n"
|
||||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// increment/decrement => not const
|
||||
void constincdec()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue