Fix 2495 incorrect sizeof error message
This commit is contained in:
parent
c7b8bd543f
commit
4cf56dac2b
|
@ -95,9 +95,18 @@ void CheckOther::checkSizeofForArrayParameter()
|
|||
const Token *declTok = Token::findmatch(_tokenizer->tokens(), "%varid%", tok->tokAt(tokIdx)->varId());
|
||||
if (declTok)
|
||||
{
|
||||
if ((Token::simpleMatch(declTok->next(), "[")) && !(Token::Match(declTok->next()->link(), "] = %str%")) && !(Token::simpleMatch(declTok->next()->link(), "] = {")) && !(Token::simpleMatch(declTok->next()->link(), "] ;")))
|
||||
if (Token::simpleMatch(declTok->next(), "["))
|
||||
{
|
||||
sizeofForArrayParameterError(tok);
|
||||
declTok = declTok->next()->link();
|
||||
// multidimensional array
|
||||
while (Token::simpleMatch(declTok->next(), "["))
|
||||
{
|
||||
declTok = declTok->next()->link();
|
||||
}
|
||||
if (!(Token::Match(declTok->next(), "= %str%")) && !(Token::simpleMatch(declTok->next(), "= {")) && !(Token::simpleMatch(declTok->next(), ";")) && !(Token::simpleMatch(declTok->next(), ",")))
|
||||
{
|
||||
sizeofForArrayParameterError(tok);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1749,6 +1749,22 @@ private:
|
|||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// ticket 2495
|
||||
check("void f() {\n"
|
||||
" static float col[][3]={\n"
|
||||
" {1,0,0},\n"
|
||||
" {0,0,1},\n"
|
||||
" {0,1,0},\n"
|
||||
" {1,0,1},\n"
|
||||
" {1,0,1},\n"
|
||||
" {1,0,1},\n"
|
||||
" };\n"
|
||||
" const int COL_MAX=sizeof(col)/sizeof(col[0]);\n"
|
||||
"}\n"
|
||||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue