Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #3785 (false positive: (style) Variable 'dinv' is assigned a va…

…lue that is never used)
  • Loading branch information...
commit 8236cd4d507156e55092c2cf844ab2de5dabc0f6 1 parent dad2fb6
Daniel Marjamäki authored
Showing with 11 additions and 2 deletions.
  1. +3 −2 lib/tokenize.cpp
  2. +8 −0 test/testtokenize.cpp
5 lib/tokenize.cpp
View
@@ -2637,11 +2637,12 @@ void Tokenizer::setVarId()
for (Token *tok = list.front(); tok; tok = tok->next()) {
// 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);
} else if (tok->str() == "{") {
scopestartvarid.push(_varId);
- if (Token::simpleMatch(tok->previous(), ")")) {
+ if (Token::simpleMatch(tok->previous(), ")") || Token::Match(tok->tokAt(-2), ") %type%")) {
executableScope.push(true);
} else {
executableScope.push(executableScope.top());
8 test/testtokenize.cpp
View
@@ -213,6 +213,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(varid45); // #3466
TEST_CASE(varid46); // struct varname
TEST_CASE(varid47); // function parameters
+ TEST_CASE(varid48); // #3785 - return (a*b)
TEST_CASE(varid_cpp_keywords_in_c_code);
TEST_CASE(varidFunctionCall1);
TEST_CASE(varidFunctionCall2);
@@ -3241,6 +3242,13 @@ class TestTokenizer : public TestFixture {
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() {
const char code[] = "void f() {\n"
" delete d;\n"
Please sign in to comment.
Something went wrong with that request. Please try again.