Fixed #1552 (false positive: function can be const (array of struct))
This commit is contained in:
parent
2c5fb55c3b
commit
2825773918
|
@ -152,8 +152,11 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo
|
|||
// Array?
|
||||
else if (Token::Match(next, "%type% %var% [") && next->next()->str() != "operator")
|
||||
{
|
||||
if (Token::findmatch(_tokenizer->tokens(), ("class|struct " + next->str()).c_str()))
|
||||
continue;
|
||||
if (!withClasses)
|
||||
{
|
||||
if (Token::findmatch(_tokenizer->tokens(), ("class|struct " + next->str()).c_str()))
|
||||
continue;
|
||||
}
|
||||
varname = next->strAt(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -108,6 +108,7 @@ private:
|
|||
TEST_CASE(const14);
|
||||
TEST_CASE(const15);
|
||||
TEST_CASE(const16); // ticket #1551
|
||||
TEST_CASE(const17); // ticket #1552
|
||||
TEST_CASE(constoperator); // operator< can often be const
|
||||
TEST_CASE(constincdec); // increment/decrement => non-const
|
||||
TEST_CASE(constReturnReference);
|
||||
|
@ -2788,6 +2789,18 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void const17()
|
||||
{
|
||||
// ticket #1552
|
||||
checkConst("class Fred {\n"
|
||||
"public:\n"
|
||||
" void set(int i, int j) { a[i].k = i; }\n"
|
||||
"private:\n"
|
||||
" struct { int k; } a[4];\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// increment/decrement => not const
|
||||
void constincdec()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue