diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 39f18b904cc..a75f07e224e 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -2280,8 +2280,11 @@ std::string Variable::getTypeName() const { std::string ret; // 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(); + if (Token::simpleMatch(typeTok->next(), "<") && typeTok->next()->link()) // skip template arguments + typeTok = typeTok->next()->link(); + } return ret; } diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index c08f6d139b8..58f1c0d28e7 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -207,6 +207,7 @@ class TestBufferOverrun : public TestFixture { TEST_CASE(array_index_negative4); TEST_CASE(array_index_negative5); // #10526 TEST_CASE(array_index_negative6); // #11349 + TEST_CASE(array_index_negative7); // #5685 TEST_CASE(array_index_for_decr); TEST_CASE(array_index_varnames); // FP: struct member #1576, FN: #1586 TEST_CASE(array_index_for_continue); // for,continue @@ -2255,6 +2256,18 @@ class TestBufferOverrun : public TestFixture { 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() { check("void f()\n" "{\n" diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index af675bcfa99..5f3cc27434c 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -6270,6 +6270,11 @@ class TestUnusedVar : public TestFixture { " myManager.theDummyTable.addRow(UnsignedIndexValue{ myNewValue }, DummyRowData{ false });\n" "}"); ASSERT_EQUALS("", errout.str()); + + functionVariableUsage("void f() {\n" + " std::list>::value_type a{ 1, 2, 3, 4 };\n" + "}\n"); + TODO_ASSERT_EQUALS("", "[test.cpp:2]: (information) --check-library: Provide configuration for std::list::value_type\n", errout.str()); } void localvarRangeBasedFor() {