diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 87c42d9f0..234523c26 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6406,6 +6406,8 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co varName = varName->next(); else --typelen; + if (isCPP() && Token::Match(varName, "public:|private:|protected:")) + continue; //skip all the pointer part bool isPointerOrRef = false; while (Token::simpleMatch(varName, "*") || Token::Match(varName, "& %name% ,")) { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index c817864ac..189b7ba5d 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -136,6 +136,7 @@ private: TEST_CASE(varid_in_class21); // #7788 TEST_CASE(varid_in_class22); // #10872 TEST_CASE(varid_in_class23); // #11293 + TEST_CASE(varid_in_class24); TEST_CASE(varid_namespace_1); // #7272 TEST_CASE(varid_namespace_2); // #7000 TEST_CASE(varid_namespace_3); // #8627 @@ -1988,6 +1989,22 @@ private: ASSERT_EQUALS(expected, tokenize(code, "test.cpp")); } + void varid_in_class24() { + const char code[] = "class A {\n" + " Q_OBJECT\n" + "public:\n" + " using QPtr = QPointer;\n" + "};\n"; + + const char expected[] = "1: class A {\n" + "2: Q_OBJECT\n" + "3: public:\n" + "4:\n" + "5: } ;\n"; + + ASSERT_EQUALS(expected, tokenize(code, "test.cpp")); + } + void varid_namespace_1() { // #7272 const char code[] = "namespace Blah {\n" " struct foo { int x;};\n"