fix #3040 (False positive - Technically the member function 'PSIPTable::SetSection' can be const.)
This commit is contained in:
parent
88b11d889c
commit
c7cb38b0b5
|
@ -1493,14 +1493,24 @@ bool CheckClass::isConstMemberFunc(const Scope *scope, const Token *tok)
|
||||||
unsigned int args = countParameters(tok);
|
unsigned int args = countParameters(tok);
|
||||||
|
|
||||||
std::list<Function>::const_iterator func;
|
std::list<Function>::const_iterator func;
|
||||||
|
unsigned int matches = 0;
|
||||||
|
unsigned int consts = 0;
|
||||||
|
|
||||||
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func)
|
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func)
|
||||||
{
|
{
|
||||||
/** @todo we need to look at the argument types when there are overloaded functions
|
/** @todo we need to look at the argument types when there are overloaded functions
|
||||||
* with the same number of arguments */
|
* with the same number of arguments */
|
||||||
if (func->tokenDef->str() == tok->str() && func->argCount() == args && func->isConst)
|
if (func->tokenDef->str() == tok->str() && func->argCount() == args)
|
||||||
return true;
|
{
|
||||||
|
matches++;
|
||||||
|
if (func->isConst)
|
||||||
|
consts++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there are multiple matches that are all const, return const
|
||||||
|
if (matches > 0 && matches == consts)
|
||||||
|
return true;
|
||||||
|
|
||||||
// not found in this class
|
// not found in this class
|
||||||
if (!scope->derivedFrom.empty())
|
if (!scope->derivedFrom.empty())
|
||||||
|
|
|
@ -178,6 +178,7 @@ private:
|
||||||
TEST_CASE(const48); // ticket #2672
|
TEST_CASE(const48); // ticket #2672
|
||||||
TEST_CASE(const49); // ticket #2795
|
TEST_CASE(const49); // ticket #2795
|
||||||
TEST_CASE(const50); // ticket #2943
|
TEST_CASE(const50); // ticket #2943
|
||||||
|
TEST_CASE(const51); // ticket #3040
|
||||||
TEST_CASE(assigningPointerToPointerIsNotAConstOperation);
|
TEST_CASE(assigningPointerToPointerIsNotAConstOperation);
|
||||||
TEST_CASE(assigningArrayElementIsNotAConstOperation);
|
TEST_CASE(assigningArrayElementIsNotAConstOperation);
|
||||||
TEST_CASE(constoperator1); // operator< can often be const
|
TEST_CASE(constoperator1); // operator< can often be const
|
||||||
|
@ -5630,6 +5631,35 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void const51() // ticket 3040
|
||||||
|
{
|
||||||
|
checkConst("class PSIPTable {\n"
|
||||||
|
"public:\n"
|
||||||
|
" PSIPTable() : _pesdata(0) { }\n"
|
||||||
|
" const unsigned char* pesdata() const { return _pesdata; }\n"
|
||||||
|
" unsigned char* pesdata() { return _pesdata; }\n"
|
||||||
|
" void SetSection(uint num) { pesdata()[6] = num; }\n"
|
||||||
|
"private:\n"
|
||||||
|
" unsigned char *_pesdata;\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkConst("class PESPacket {\n"
|
||||||
|
"public:\n"
|
||||||
|
" PESPacket() : _pesdata(0) { }\n"
|
||||||
|
" const unsigned char* pesdata() const { return _pesdata; }\n"
|
||||||
|
" unsigned char* pesdata() { return _pesdata; }\n"
|
||||||
|
"private:\n"
|
||||||
|
" unsigned char *_pesdata;\n"
|
||||||
|
"};\n"
|
||||||
|
"class PSIPTable : public PESPacket\n"
|
||||||
|
"{\n"
|
||||||
|
"public:\n"
|
||||||
|
" void SetSection(uint num) { pesdata()[6] = num; }\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void assigningPointerToPointerIsNotAConstOperation()
|
void assigningPointerToPointerIsNotAConstOperation()
|
||||||
{
|
{
|
||||||
checkConst("struct s\n"
|
checkConst("struct s\n"
|
||||||
|
|
Loading…
Reference in New Issue