From 8f49eb6a7ef691b3a53e008c6ada9a3aa2b792cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 29 Oct 2011 18:22:58 +0200 Subject: [PATCH] Tokenizer: Make sure that friend classes don't get varid. Ticket: #2962 --- lib/tokenize.cpp | 3 +++ test/testtokenize.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) 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"