From 5f67bc1b0a432060dbe050562be98dadabaeae91 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 17 Mar 2014 16:15:42 +0100 Subject: [PATCH] Fixed varId problem #5293 (and its duplicate #5577): Classes inside functions are non-executable scopes. --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 8f7425b1a..f07c1d5c3 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2417,7 +2417,7 @@ void Tokenizer::setVarId() if (tok->strAt(-1) == ")" || Token::Match(tok->tokAt(-2), ") %type%")) { executableScope.push(true); } else { - executableScope.push(executableScope.top()); + executableScope.push(tok->strAt(-1) == "else"); scopeInfo.push(variableId); } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 9a2cbd76b..966376b92 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -303,6 +303,7 @@ private: TEST_CASE(varid_rvalueref); TEST_CASE(varid_arrayFuncPar); // #5294 TEST_CASE(varid_sizeofPassed); // #5295 + TEST_CASE(varid_classInFunction); // #5293 TEST_CASE(varidclass1); 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() { const std::string actual = tokenizeDebugListing( "class Fred\n"