Fixed #1847 (False positive: Method using std::swap<>() can be declared const)

This commit is contained in:
Robert Reif 2010-07-13 08:01:57 +02:00 committed by Daniel Marjamäki
parent 414dbdb295
commit 225a529471
2 changed files with 16 additions and 1 deletions

View File

@ -1996,7 +1996,8 @@ bool CheckClass::checkConstFunc(const std::string &classname, const Var *varlist
} }
// function call.. // 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; isconst = false;
break; break;

View File

@ -126,6 +126,7 @@ private:
TEST_CASE(const23); // ticket #1699 TEST_CASE(const23); // ticket #1699
TEST_CASE(const24); // ticket #1708 TEST_CASE(const24); // ticket #1708
TEST_CASE(const25); // ticket #1724 TEST_CASE(const25); // ticket #1724
TEST_CASE(const26); // ticket #1847
TEST_CASE(constoperator1); // operator< can often be const TEST_CASE(constoperator1); // operator< can often be const
TEST_CASE(constoperator2); // operator<< TEST_CASE(constoperator2); // operator<<
TEST_CASE(constincdec); // increment/decrement => non-const 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()); 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 // increment/decrement => not const
void constincdec() void constincdec()
{ {