Skip to content

Commit

Permalink
Fixed #3785 (false positive: (style) Variable 'dinv' is assigned a va…
Browse files Browse the repository at this point in the history
…lue that is never used)
  • Loading branch information
Daniel Marjamäki committed May 8, 2012
1 parent dad2fb6 commit 8236cd4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/tokenize.cpp
Expand Up @@ -2637,11 +2637,12 @@ void Tokenizer::setVarId()
for (Token *tok = list.front(); tok; tok = tok->next()) { for (Token *tok = list.front(); tok; tok = tok->next()) {


// scope info to handle shadow variables.. // scope info to handle shadow variables..
if (tok->str() == "(" && Token::simpleMatch(tok->link(), ") {")) { if (tok->str() == "(" &&
(Token::simpleMatch(tok->link(), ") {") || Token::Match(tok->link(), ") %type% {"))) {
scopeInfo.push(variableId); scopeInfo.push(variableId);
} else if (tok->str() == "{") { } else if (tok->str() == "{") {
scopestartvarid.push(_varId); scopestartvarid.push(_varId);
if (Token::simpleMatch(tok->previous(), ")")) { if (Token::simpleMatch(tok->previous(), ")") || Token::Match(tok->tokAt(-2), ") %type%")) {
executableScope.push(true); executableScope.push(true);
} else { } else {
executableScope.push(executableScope.top()); executableScope.push(executableScope.top());
Expand Down
8 changes: 8 additions & 0 deletions test/testtokenize.cpp
Expand Up @@ -213,6 +213,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(varid45); // #3466 TEST_CASE(varid45); // #3466
TEST_CASE(varid46); // struct varname TEST_CASE(varid46); // struct varname
TEST_CASE(varid47); // function parameters TEST_CASE(varid47); // function parameters
TEST_CASE(varid48); // #3785 - return (a*b)
TEST_CASE(varid_cpp_keywords_in_c_code); TEST_CASE(varid_cpp_keywords_in_c_code);
TEST_CASE(varidFunctionCall1); TEST_CASE(varidFunctionCall1);
TEST_CASE(varidFunctionCall2); TEST_CASE(varidFunctionCall2);
Expand Down Expand Up @@ -3241,6 +3242,13 @@ class TestTokenizer : public TestFixture {
tokenizeDebugListing(code, false, "test.cpp")); tokenizeDebugListing(code, false, "test.cpp"));
} }


void varid48() { // #3785 - return (a*b)
const std::string code("int X::f(int b) const { return(a*b); }");
ASSERT_EQUALS("\n\n##file 0\n"
"1: int X :: f ( int b@1 ) const { return ( a * b@1 ) ; }\n",
tokenizeDebugListing(code, false, "test.c"));
}

void varid_cpp_keywords_in_c_code() { void varid_cpp_keywords_in_c_code() {
const char code[] = "void f() {\n" const char code[] = "void f() {\n"
" delete d;\n" " delete d;\n"
Expand Down

0 comments on commit 8236cd4

Please sign in to comment.