diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2fe7c68d5..a10f9117d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3370,6 +3370,9 @@ void Tokenizer::setVarId() while (Token::Match(tok, "const|static|extern|public:|private:|protected:|;|mutable")) tok = tok->next(); + if (tok && tok->str() == "friend") + continue; + // skip global namespace prefix if (Token::simpleMatch(tok, "::")) tok = tok->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 5e960076f..a9a5b93e0 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -210,6 +210,7 @@ private: TEST_CASE(varidclass11); // variable declaration below usage TEST_CASE(varidclass12); TEST_CASE(varidclass13); + TEST_CASE(varidclass14); TEST_CASE(file1); TEST_CASE(file2); @@ -3582,6 +3583,35 @@ private: ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } + void varidclass14() { + // don't give friend classes varid + { + const std::string code("class A {\n" + "friend class B;\n" + "}"); + + const std::string expected("\n\n##file 0\n" + "1: class A {\n" + "2: friend class B ;\n" + "3: }\n"); + + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); + } + + { + const std::string code("class A {\n" + "private: friend class B;\n" + "}"); + + const std::string expected("\n\n##file 0\n" + "1: class A {\n" + "2: private: friend class B ;\n" + "3: }\n"); + + ASSERT_EQUALS(expected, tokenizeDebugListing(code)); + } + } + void file1() { const char code[] = "a1\n" "#file \"b\"\n"