Fixed #4988 (Tokenizer::setVarId: Wrong varid for inline function parameter)
This commit is contained in:
parent
324257ef52
commit
8b384f8ee5
|
@ -2598,6 +2598,7 @@ void Tokenizer::setVarIdPass1()
|
|||
scopeStack.push(VarIdScopeInfo());
|
||||
std::stack<const Token *> functionDeclEndStack;
|
||||
bool initlist = false;
|
||||
bool inlineFunction = false;
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (!functionDeclEndStack.empty() && tok == functionDeclEndStack.top()) {
|
||||
functionDeclEndStack.pop();
|
||||
|
@ -2625,6 +2626,8 @@ void Tokenizer::setVarIdPass1()
|
|||
scopeInfo.push(variableId);
|
||||
}
|
||||
} else if (Token::Match(tok, "{|}")) {
|
||||
inlineFunction = false;
|
||||
|
||||
const Token * const startToken = (tok->str() == "{") ? tok : tok->link();
|
||||
|
||||
// parse anonymous unions as part of the current scope
|
||||
|
@ -2682,7 +2685,7 @@ void Tokenizer::setVarIdPass1()
|
|||
Token::Match(tok, "[;{}]") ||
|
||||
(tok->str() == "(" && isFunctionHead(tok,"{")) ||
|
||||
(tok->str() == "(" && !scopeStack.top().isExecutable && isFunctionHead(tok,";:")) ||
|
||||
(tok->str() == "," && !scopeStack.top().isExecutable) ||
|
||||
(tok->str() == "," && (!scopeStack.top().isExecutable || inlineFunction)) ||
|
||||
(tok->isName() && endsWith(tok->str(), ':')))) {
|
||||
|
||||
// No variable declarations in sizeof
|
||||
|
@ -2717,6 +2720,9 @@ void Tokenizer::setVarIdPass1()
|
|||
syntaxError(errTok);
|
||||
}
|
||||
if (decl) {
|
||||
if (tok->str() == "(" && isFunctionHead(tok,"{") && scopeStack.top().isExecutable)
|
||||
inlineFunction = true;
|
||||
|
||||
const Token* prev2 = tok2->previous();
|
||||
if (Token::Match(prev2, "%type% [;[=,)]") && tok2->previous()->str() != "const")
|
||||
;
|
||||
|
|
|
@ -91,6 +91,7 @@ private:
|
|||
TEST_CASE(varid58); // #6638: for loop in for condition
|
||||
TEST_CASE(varid59); // #6696
|
||||
TEST_CASE(varid60); // #7267 cast '(unsigned x)10'
|
||||
TEST_CASE(varid61); // #4988 inline function
|
||||
TEST_CASE(varid_cpp_keywords_in_c_code);
|
||||
TEST_CASE(varid_cpp_keywords_in_c_code2); // #5373: varid=0 for argument called "delete"
|
||||
TEST_CASE(varidFunctionCall1);
|
||||
|
@ -1050,6 +1051,16 @@ private:
|
|||
tokenize("a=(x y)10;", false));
|
||||
}
|
||||
|
||||
void varid61() {
|
||||
const char code[] = "void foo(int b) {\n"
|
||||
" void bar(int a, int b) {}\n"
|
||||
"}";
|
||||
const char expected[] = "1: void foo ( int b@1 ) {\n"
|
||||
"2: void bar ( int a@2 , int b@3 ) { }\n"
|
||||
"3: }\n";
|
||||
ASSERT_EQUALS(expected, tokenize(code, false));
|
||||
}
|
||||
|
||||
void varid_cpp_keywords_in_c_code() {
|
||||
const char code[] = "void f() {\n"
|
||||
" delete d;\n"
|
||||
|
|
Loading…
Reference in New Issue