Tokenizer: Make sure that friend classes don't get varid. Ticket: #2962

This commit is contained in:
Daniel Marjamäki 2011-10-29 18:22:58 +02:00
parent d75ef01d2b
commit 8f49eb6a7e
2 changed files with 33 additions and 0 deletions

View File

@ -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();

View File

@ -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"