Skip to content

Commit 0f90070

Browse files
committed
fixed assumption in setVarIdParseDeclaration() that isC() == false implies isHeader() == true / added TokenList::isHeader() and Tokenizer::isHeader()
1 parent 184d2d4 commit 0f90070

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

lib/tokenize.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4156,7 +4156,7 @@ void VariableMap::addVariable(const std::string& varname, bool globalNamespace)
41564156
it->second = ++mVarId;
41574157
}
41584158

4159-
static bool setVarIdParseDeclaration(Token** tok, const VariableMap& variableMap, bool executableScope, bool cpp, bool c)
4159+
static bool setVarIdParseDeclaration(Token** tok, const VariableMap& variableMap, bool executableScope)
41604160
{
41614161
const Token* const tok1 = *tok;
41624162
Token* tok2 = *tok;
@@ -4174,14 +4174,14 @@ static bool setVarIdParseDeclaration(Token** tok, const VariableMap& variableMap
41744174
tok2 = tok2->linkAt(1)->next();
41754175
continue;
41764176
}
4177-
if (cpp && Token::Match(tok2, "namespace|public|private|protected"))
4177+
if (tok2->isCpp() && Token::Match(tok2, "namespace|public|private|protected"))
41784178
return false;
4179-
if (cpp && Token::simpleMatch(tok2, "decltype (")) {
4179+
if (tok2->isCpp() && Token::simpleMatch(tok2, "decltype (")) {
41804180
typeCount = 1;
41814181
tok2 = tok2->linkAt(1)->next();
41824182
continue;
41834183
}
4184-
if (Token::Match(tok2, "struct|union|enum") || (!c && Token::Match(tok2, "class|typename"))) {
4184+
if (Token::Match(tok2, "struct|union|enum") || (tok2->isCpp() && Token::Match(tok2, "class|typename"))) {
41854185
hasstruct = true;
41864186
typeCount = 0;
41874187
singleNameCount = 0;
@@ -4197,8 +4197,8 @@ static bool setVarIdParseDeclaration(Token** tok, const VariableMap& variableMap
41974197
++typeCount;
41984198
++singleNameCount;
41994199
}
4200-
} else if (!c && ((TemplateSimplifier::templateParameters(tok2) > 0) ||
4201-
Token::simpleMatch(tok2, "< >") /* Ticket #4764 */)) {
4200+
} else if (tok2->isCpp() && ((TemplateSimplifier::templateParameters(tok2) > 0) ||
4201+
Token::simpleMatch(tok2, "< >") /* Ticket #4764 */)) {
42024202
const Token *start = *tok;
42034203
if (Token::Match(start->previous(), "%or%|%oror%|&&|&|^|+|-|*|/"))
42044204
return false;
@@ -4263,7 +4263,7 @@ static bool setVarIdParseDeclaration(Token** tok, const VariableMap& variableMap
42634263
}
42644264
}
42654265

4266-
if (cpp && tok3 && Token::simpleMatch(tok3->previous(), "] (") &&
4266+
if (tok3 && tok3->isCpp() && Token::simpleMatch(tok3->previous(), "] (") &&
42674267
(Token::simpleMatch(tok3->link(), ") {") || Token::Match(tok3->link(), ") . %name%")))
42684268
isLambdaArg = true;
42694269
}
@@ -4683,7 +4683,7 @@ void Tokenizer::setVarIdPass1()
46834683
}
46844684

46854685
try { /* Ticket #8151 */
4686-
decl = setVarIdParseDeclaration(&tok2, variableMap, scopeStack.top().isExecutable, isCPP(), isC());
4686+
decl = setVarIdParseDeclaration(&tok2, variableMap, scopeStack.top().isExecutable);
46874687
} catch (const Token * errTok) {
46884688
syntaxError(errTok);
46894689
}

test/testvarid.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2812,14 +2812,30 @@ class TestVarID : public TestFixture {
28122812
}
28132813

28142814
void varid_header() {
2815+
ASSERT_EQUALS("1: class A@1 ;\n"
2816+
"2: struct B {\n"
2817+
"3: void setData ( const A@1 & a ) ;\n"
2818+
"4: } ;\n",
2819+
tokenize("class A;\n"
2820+
"struct B {\n"
2821+
" void setData(const A & a);\n"
2822+
"}; ", "test.h"));
28152823
ASSERT_EQUALS("1: class A ;\n"
28162824
"2: struct B {\n"
28172825
"3: void setData ( const A & a@1 ) ;\n"
28182826
"4: } ;\n",
28192827
tokenize("class A;\n"
28202828
"struct B {\n"
28212829
" void setData(const A & a);\n"
2822-
"}; ", "test.h"));
2830+
"}; ", "test.hpp"));
2831+
ASSERT_EQUALS("1: void f ( )\n"
2832+
"2: {\n"
2833+
"3: int class@1 ;\n"
2834+
"4: }\n",
2835+
tokenize("void f()\n"
2836+
"{\n"
2837+
" int class;\n"
2838+
"}", "test.h"));
28232839
}
28242840

28252841
void varid_rangeBasedFor() {

0 commit comments

Comments
 (0)