Fixed VarId accidentially assigned to case labels.

This commit is contained in:
PKEuS 2015-10-26 21:24:53 +01:00
parent dfdc0f6b99
commit 24882fb53a
3 changed files with 26 additions and 2 deletions

View File

@ -2749,7 +2749,9 @@ void Tokenizer::setVarId()
bool decl = setVarIdParseDeclaration(&tok2, variableId, scopeStack.top().isExecutable, isCPP(), isC());
if (decl) {
const Token* prev2 = tok2->previous();
if (Token::Match(prev2, "%type% [;[=,):]") && tok2->previous()->str() != "const")
if (Token::Match(prev2, "%type% [;[=,)]") && tok2->previous()->str() != "const")
;
else if (Token::Match(prev2, "%type% :") && tok->strAt(-1) == "for")
;
else if (Token::Match(prev2, "%type% ( !!)") && Token::simpleMatch(tok2->link(), ") ;")) {
// In C++ , a variable can't be called operator+ or something like that.

View File

@ -687,7 +687,8 @@ private:
return;
ASSERT(db->scopeList.back().type == Scope::eFor);
ASSERT_EQUALS(2, db->getVariableListSize());
if (db->getVariableListSize() < 2)
return;
const Variable* e = db->getVariableFromVarId(1);
ASSERT(e && e->isReference() && e->isLocal());
}

View File

@ -2175,6 +2175,27 @@ private:
" for (auto e : array)\n"
" foo(e);\n"
"};"));
// Labels are no variables
ASSERT_EQUALS("\n\n##file 0\n"
"1: void foo ( ) {\n"
"2: switch ( event . key . keysym . sym ) {\n"
"3: case SDLK_LEFT : ;\n"
"4: break ;\n"
"5: case SDLK_RIGHT : ;\n"
"6: delta = 1 ;\n"
"7: break ;\n"
"8: }\n"
"9: }\n",
tokenize("void foo() {\n"
" switch (event.key.keysym.sym) {\n"
" case SDLK_LEFT:\n"
" break;\n"
" case SDLK_RIGHT:\n"
" delta = 1;\n"
" break;\n"
" }\n"
"}", false, "test.c"));
}
void varidclass1() {