* Fix #10466 FP constVariable with pointer typedef * Fix flag check * Use isStatic()
This commit is contained in:
parent
0e1a0b97ed
commit
7721cd14b6
|
@ -1549,11 +1549,13 @@ void CheckOther::checkConstPointer()
|
||||||
continue;
|
continue;
|
||||||
const Token* const nameTok = tok->variable()->nameToken();
|
const Token* const nameTok = tok->variable()->nameToken();
|
||||||
// declarations of (static) pointers are (not) split up, array declarations are never split up
|
// declarations of (static) pointers are (not) split up, array declarations are never split up
|
||||||
if (tok == nameTok && (!Token::simpleMatch(tok->variable()->typeStartToken()->previous(), "static") || Token::simpleMatch(nameTok->next(), "[")))
|
if (tok == nameTok && (!tok->variable()->isStatic() || Token::simpleMatch(nameTok->next(), "[")) &&
|
||||||
|
// range-based for loop
|
||||||
|
!(Token::simpleMatch(nameTok->astParent(), ":") && Token::simpleMatch(nameTok->astParent()->astParent(), "(")))
|
||||||
continue;
|
continue;
|
||||||
if (!tok->valueType())
|
if (!tok->valueType())
|
||||||
continue;
|
continue;
|
||||||
if (tok->valueType()->pointer == 0 || tok->valueType()->constness > 0)
|
if (tok->valueType()->pointer == 0 || (tok->valueType()->constness & 1))
|
||||||
continue;
|
continue;
|
||||||
if (nonConstPointers.find(tok->variable()) != nonConstPointers.end())
|
if (nonConstPointers.find(tok->variable()) != nonConstPointers.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -6150,7 +6150,7 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
|
||||||
setAutoTokenProperties(autoToken);
|
setAutoTokenProperties(autoToken);
|
||||||
ValueType varvt(autovt);
|
ValueType varvt(autovt);
|
||||||
if (isconst)
|
if (isconst)
|
||||||
varvt.constness |= 1;
|
varvt.constness |= (1 << varvt.pointer);
|
||||||
setValueType(parent->previous(), varvt);
|
setValueType(parent->previous(), varvt);
|
||||||
Variable * var = const_cast<Variable *>(parent->previous()->variable());
|
Variable * var = const_cast<Variable *>(parent->previous()->variable());
|
||||||
if (var) {
|
if (var) {
|
||||||
|
|
|
@ -2997,6 +2997,44 @@ private:
|
||||||
" if (i[0] == 0) {}\n"
|
" if (i[0] == 0) {}\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #10466
|
||||||
|
check("void f(const std::vector<int*>& v) {\n"
|
||||||
|
" for (const auto& p : v)\n"
|
||||||
|
" if (p == nullptr) {}\n"
|
||||||
|
" for (const auto* p : v)\n"
|
||||||
|
" if (p == nullptr) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f(std::vector<int*>& v) {\n"
|
||||||
|
" for (const auto& p : v)\n"
|
||||||
|
" if (p == nullptr) {}\n"
|
||||||
|
" for (const auto* p : v)\n"
|
||||||
|
" if (p == nullptr) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared with const\n", errout.str());
|
||||||
|
|
||||||
|
check("void f(std::vector<const int*>& v) {\n"
|
||||||
|
" for (const auto& p : v)\n"
|
||||||
|
" if (p == nullptr) {}\n"
|
||||||
|
" for (const auto* p : v)\n"
|
||||||
|
" if (p == nullptr) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:1]: (style) Parameter 'v' can be declared with const\n", errout.str());
|
||||||
|
|
||||||
|
check("void f(const std::vector<const int*>& v) {\n"
|
||||||
|
" for (const auto& p : v)\n"
|
||||||
|
" if (p == nullptr) {}\n"
|
||||||
|
" for (const auto* p : v)\n"
|
||||||
|
" if (p == nullptr) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f(const int* const p) {\n"
|
||||||
|
" if (p == nullptr) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void switchRedundantAssignmentTest() {
|
void switchRedundantAssignmentTest() {
|
||||||
|
@ -9112,7 +9150,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("", errout.str());
|
ASSERT_EQUALS("[test.c:1]: (style) Parameter 'argv' can be declared with const\n", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int x = 0;\n"
|
" int x = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue