Fixed varId problem #5293 (and its duplicate #5577): Classes inside functions are non-executable scopes.

This commit is contained in:
PKEuS 2014-03-17 16:15:42 +01:00
parent 06618b31bb
commit 5f67bc1b0a
2 changed files with 18 additions and 1 deletions

View File

@ -2417,7 +2417,7 @@ void Tokenizer::setVarId()
if (tok->strAt(-1) == ")" || Token::Match(tok->tokAt(-2), ") %type%")) { if (tok->strAt(-1) == ")" || Token::Match(tok->tokAt(-2), ") %type%")) {
executableScope.push(true); executableScope.push(true);
} else { } else {
executableScope.push(executableScope.top()); executableScope.push(tok->strAt(-1) == "else");
scopeInfo.push(variableId); scopeInfo.push(variableId);
} }
} }

View File

@ -303,6 +303,7 @@ private:
TEST_CASE(varid_rvalueref); TEST_CASE(varid_rvalueref);
TEST_CASE(varid_arrayFuncPar); // #5294 TEST_CASE(varid_arrayFuncPar); // #5294
TEST_CASE(varid_sizeofPassed); // #5295 TEST_CASE(varid_sizeofPassed); // #5295
TEST_CASE(varid_classInFunction); // #5293
TEST_CASE(varidclass1); TEST_CASE(varidclass1);
TEST_CASE(varidclass2); TEST_CASE(varidclass2);
@ -4719,6 +4720,22 @@ private:
"}")); "}"));
} }
void varid_classInFunction() {
ASSERT_EQUALS("\n\n##file 0\n"
"1: void AddSuppression ( ) {\n"
"2: class QErrorLogger {\n"
"3: void reportErr ( ErrorLogger :: ErrorMessage & msg@1 ) {\n"
"4: }\n"
"5: } ;\n"
"6: }\n",
tokenizeDebugListing("void AddSuppression() {\n"
" class QErrorLogger {\n"
" void reportErr(ErrorLogger::ErrorMessage &msg) {\n"
" }\n"
" }; \n"
"}"));
}
void varidclass1() { void varidclass1() {
const std::string actual = tokenizeDebugListing( const std::string actual = tokenizeDebugListing(
"class Fred\n" "class Fred\n"