Fix FP constVariable with 2D array. (#4228)
Test case #8717 was actually a FP as well.
This commit is contained in:
parent
650f4099d2
commit
f1212e66f7
|
@ -1565,11 +1565,14 @@ void CheckOther::checkConstPointer()
|
||||||
if (Token::simpleMatch(gparent, "return"))
|
if (Token::simpleMatch(gparent, "return"))
|
||||||
continue;
|
continue;
|
||||||
else if (Token::Match(gparent, "%assign%") && parent == gparent->astOperand2()) {
|
else if (Token::Match(gparent, "%assign%") && parent == gparent->astOperand2()) {
|
||||||
bool takingRef = false;
|
bool takingRef = false, nonConstPtrAssignment = false;
|
||||||
const Token *lhs = gparent->astOperand1();
|
const Token *lhs = gparent->astOperand1();
|
||||||
if (lhs && lhs->variable() && lhs->variable()->isReference() && lhs->variable()->nameToken() == lhs)
|
if (lhs && lhs->variable() && lhs->variable()->isReference() && lhs->variable()->nameToken() == lhs)
|
||||||
takingRef = true;
|
takingRef = true;
|
||||||
if (!takingRef)
|
if (lhs && lhs->valueType() && lhs->valueType()->pointer && (lhs->valueType()->constness & 1) == 0 &&
|
||||||
|
parent->valueType() && parent->valueType()->pointer)
|
||||||
|
nonConstPtrAssignment = true;
|
||||||
|
if (!takingRef && !nonConstPtrAssignment)
|
||||||
continue;
|
continue;
|
||||||
} else if (Token::simpleMatch(gparent, "[") && gparent->astOperand2() == parent)
|
} else if (Token::simpleMatch(gparent, "[") && gparent->astOperand2() == parent)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -3230,6 +3230,14 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n"
|
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'p' can be declared as pointer to const\n"
|
||||||
"[test.cpp:5]: (style) Variable 'p' can be declared as pointer to const\n",
|
"[test.cpp:5]: (style) Variable 'p' can be declared as pointer to const\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
|
||||||
|
check("void f() {\n"
|
||||||
|
" char a[1][1];\n"
|
||||||
|
" char* b[1];\n"
|
||||||
|
" b[0] = a[0];\n"
|
||||||
|
" **b = 0;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void switchRedundantAssignmentTest() {
|
void switchRedundantAssignmentTest() {
|
||||||
|
@ -9383,7 +9391,7 @@ private:
|
||||||
" int local_argc = 0;\n"
|
" int local_argc = 0;\n"
|
||||||
" local_argv[local_argc++] = argv[0];\n"
|
" local_argv[local_argc++] = argv[0];\n"
|
||||||
"}\n", "test.c");
|
"}\n", "test.c");
|
||||||
ASSERT_EQUALS("[test.c:1]: (style) Parameter 'argv' can be declared as const array\n", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int x = 0;\n"
|
" int x = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue