diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 234523c2663..c4d3a84393f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6406,7 +6406,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co varName = varName->next(); else --typelen; - if (isCPP() && Token::Match(varName, "public:|private:|protected:")) + if (isCPP() && Token::Match(varName, "public:|private:|protected:|using")) continue; //skip all the pointer part bool isPointerOrRef = false; diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 189b7ba5d04..587166ac151 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -1990,18 +1990,28 @@ class TestVarID : public TestFixture { } 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"; + const char *code{}, *expected{}; + + code = "class A {\n" + " Q_OBJECT\n" + "public:\n" + " using QPtr = QPointer;\n" + "};\n"; + expected = "1: class A {\n" + "2: Q_OBJECT\n" + "3: public:\n" + "4:\n" + "5: } ;\n"; + ASSERT_EQUALS(expected, tokenize(code, "test.cpp")); + code = "class A {\n" + " Q_OBJECT\n" + " using QPtr = QPointer;\n" + "};\n"; + expected = "1: class A {\n" + "2: Q_OBJECT\n" + "3:\n" + "4: } ;\n"; ASSERT_EQUALS(expected, tokenize(code, "test.cpp")); }