diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 9d61cd552..cd7939285 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -177,9 +177,20 @@ CheckClass::Var *CheckClass::getVarList(const Token *tok1, bool withClasses, boo else if (withClasses && (Token::Match(next, "%type% :: %type% <") || Token::Match(next, "%type% <"))) { - while (next && next->str() != ">") - next = next->next(); - if (Token::Match(next, "> %var% ;")) + // find matching ">" + int level = 0; + for (; next; next = next->next()) + { + if (next->str() == "<") + level++; + else if (next->str() == ">") + { + level--; + if (level == 0) + break; + } + } + if (next && Token::Match(next, "> %var% ;")) varname = next->strAt(1); } diff --git a/test/testclass.cpp b/test/testclass.cpp index 8cc326f3e..3f02db551 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -118,6 +118,7 @@ private: TEST_CASE(const20); // ticket #1602 TEST_CASE(const21); // ticket #1683 TEST_CASE(const22); + TEST_CASE(const23); // ticket #1699 TEST_CASE(constoperator1); // operator< can often be const TEST_CASE(constoperator2); // operator<< TEST_CASE(constincdec); // increment/decrement => non-const @@ -3331,6 +3332,19 @@ private: ASSERT_EQUALS("", errout.str()); } + void const23() + { + checkConst("class Class {\n" + "public:\n" + " typedef Template Type;\n" + " typedef Template2 Type2;\n" + " void set_member(Type2 m) { _m = m; }\n" + "private:\n" + " Type2 _m;\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + // increment/decrement => not const void constincdec() {