Fixed setVarId-Bugs #5294 and #5295.

This commit is contained in:
PKEuS 2014-03-17 14:19:00 +01:00
parent fe94d9b4d5
commit 521734faa2
2 changed files with 23 additions and 2 deletions

View File

@ -2231,7 +2231,7 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
// Check if array declaration is valid (#2638)
// invalid declaration: AAA a[4] = 0;
if (typeCount >= 2 && tok2 && tok2->str() == "[") {
if (typeCount >= 2 && tok2 && tok2->str() == "[" && executableScope) {
const Token *tok3 = tok2;
while (tok3 && tok3->str() == "[") {
tok3 = tok3->link()->next();
@ -2495,7 +2495,7 @@ void Tokenizer::setVarId()
continue;
const Token *tok3 = tok2->next();
if (!tok3->isStandardType() && tok3->str() != "void" && !Token::Match(tok3,"struct|union|class %type%") && tok3->str() != "." && !setVarIdParseDeclaration(&tok3,variableId,executableScope.top(),isCPP())) {
if (!tok3->isStandardType() && tok3->str() != "void" && !Token::Match(tok3, "struct|union|class %type%") && tok3->str() != "." && (notstart.find(tok3->str()) != notstart.end() ||!setVarIdParseDeclaration(&tok3, variableId, executableScope.top(), isCPP()))) {
variableId[tok2->previous()->str()] = ++_varId;
tok = tok2->previous();
}

View File

@ -301,6 +301,8 @@ private:
TEST_CASE(varid_variadicFunc);
TEST_CASE(varid_typename); // #4644
TEST_CASE(varid_rvalueref);
TEST_CASE(varid_arrayFuncPar); // #5294
TEST_CASE(varid_sizeofPassed); // #5295
TEST_CASE(varidclass1);
TEST_CASE(varidclass2);
@ -4698,6 +4700,25 @@ private:
"};"));
}
void varid_arrayFuncPar() {
ASSERT_EQUALS("\n\n##file 0\n"
"1: void check ( const char fname@1 [ ] = 0 ) { }\n", tokenizeDebugListing("void check( const char fname[] = 0) { }"));
}
void varid_sizeofPassed() {
ASSERT_EQUALS("\n\n##file 0\n"
"1: void which_test ( ) {\n"
"2: const char * argv@1 [ 2 ] = { \"./test_runner\" , \"TestClass\" } ;\n"
"3: options args@2 ( sizeof argv@1 / sizeof ( argv@1 [ 0 ] ) , argv@1 ) ;\n"
"4: args@2 . which_test ( ) ;\n"
"5: }\n",
tokenizeDebugListing("void which_test() {\n"
" const char* argv[] = { \"./test_runner\", \"TestClass\" };\n"
" options args(sizeof argv / sizeof argv[0], argv);\n"
" args.which_test();\n"
"}"));
}
void varidclass1() {
const std::string actual = tokenizeDebugListing(
"class Fred\n"