Improve <type-checks><unusedvar> error message (#4735)
This commit is contained in:
parent
a0b1285f4a
commit
a0f51d1e21
|
@ -2280,8 +2280,11 @@ std::string Variable::getTypeName() const
|
||||||
{
|
{
|
||||||
std::string ret;
|
std::string ret;
|
||||||
// TODO: For known types, generate the full type name
|
// TODO: For known types, generate the full type name
|
||||||
for (const Token *typeTok = mTypeStartToken; Token::Match(typeTok, "%name%|::") && typeTok->varId() == 0; typeTok = typeTok->next())
|
for (const Token *typeTok = mTypeStartToken; Token::Match(typeTok, "%name%|::") && typeTok->varId() == 0; typeTok = typeTok->next()) {
|
||||||
ret += typeTok->str();
|
ret += typeTok->str();
|
||||||
|
if (Token::simpleMatch(typeTok->next(), "<") && typeTok->next()->link()) // skip template arguments
|
||||||
|
typeTok = typeTok->next()->link();
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -207,6 +207,7 @@ private:
|
||||||
TEST_CASE(array_index_negative4);
|
TEST_CASE(array_index_negative4);
|
||||||
TEST_CASE(array_index_negative5); // #10526
|
TEST_CASE(array_index_negative5); // #10526
|
||||||
TEST_CASE(array_index_negative6); // #11349
|
TEST_CASE(array_index_negative6); // #11349
|
||||||
|
TEST_CASE(array_index_negative7); // #5685
|
||||||
TEST_CASE(array_index_for_decr);
|
TEST_CASE(array_index_for_decr);
|
||||||
TEST_CASE(array_index_varnames); // FP: struct member #1576, FN: #1586
|
TEST_CASE(array_index_varnames); // FP: struct member #1576, FN: #1586
|
||||||
TEST_CASE(array_index_for_continue); // for,continue
|
TEST_CASE(array_index_for_continue); // for,continue
|
||||||
|
@ -2271,6 +2272,18 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #5685
|
||||||
|
void array_index_negative7()
|
||||||
|
{
|
||||||
|
check("void f() {\n"
|
||||||
|
" int i = -9;\n"
|
||||||
|
" int a[5];\n"
|
||||||
|
" for (; i < 5; i++)\n"
|
||||||
|
" a[i] = 1;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[5]' accessed at index -9, which is out of bounds.\n", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void array_index_for_decr() {
|
void array_index_for_decr() {
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
|
@ -6270,6 +6270,11 @@ private:
|
||||||
" myManager.theDummyTable.addRow(UnsignedIndexValue{ myNewValue }, DummyRowData{ false });\n"
|
" myManager.theDummyTable.addRow(UnsignedIndexValue{ myNewValue }, DummyRowData{ false });\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
functionVariableUsage("void f() {\n"
|
||||||
|
" std::list<std::list<int>>::value_type a{ 1, 2, 3, 4 };\n"
|
||||||
|
"}\n");
|
||||||
|
TODO_ASSERT_EQUALS("", "[test.cpp:2]: (information) --check-library: Provide <type-checks><unusedvar> configuration for std::list::value_type\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void localvarRangeBasedFor() {
|
void localvarRangeBasedFor() {
|
||||||
|
|
Loading…
Reference in New Issue