diff --git a/lib/checkother.cpp b/lib/checkother.cpp index a4eb1216d..74cb042a9 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -946,7 +946,7 @@ void CheckOther::functionVariableUsage() break; } else if (Token::Match(tok, "struct|union|class {") || - Token::Match(tok, "struct|union|class %type% {")) + Token::Match(tok, "struct|union|class %type% {|:")) { while (tok->str() != "{") tok = tok->next(); diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 7686cf791..d79581f28 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -104,6 +104,7 @@ private: TEST_CASE(localvarFor); // for ( ; var; ) TEST_CASE(localvarShift); // 1 >> var TEST_CASE(localvarCast); + TEST_CASE(localvarClass); } void structmember1() @@ -1881,6 +1882,17 @@ private: ASSERT_EQUALS(std::string(""), errout.str()); } + void localvarClass() + { + functionVariableUsage("int foo()\n" + "{\n" + " class B : public A {\n" + " int a;\n" + " int f() { return a; }\n" + " } b;\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + } }; REGISTER_TEST(TestUnusedVar)