Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 May 08, 2012
5  lib/tokenize.cpp
@@ -2637,11 +2637,12 @@ void Tokenizer::setVarId()
2637 2637
     for (Token *tok = list.front(); tok; tok = tok->next()) {
2638 2638
 
2639 2639
         // scope info to handle shadow variables..
2640  
-        if (tok->str() == "(" && Token::simpleMatch(tok->link(), ") {")) {
  2640
+        if (tok->str() == "(" &&
  2641
+            (Token::simpleMatch(tok->link(), ") {") || Token::Match(tok->link(), ") %type% {"))) {
2641 2642
             scopeInfo.push(variableId);
2642 2643
         } else if (tok->str() == "{") {
2643 2644
             scopestartvarid.push(_varId);
2644  
-            if (Token::simpleMatch(tok->previous(), ")")) {
  2645
+            if (Token::simpleMatch(tok->previous(), ")") || Token::Match(tok->tokAt(-2), ") %type%")) {
2645 2646
                 executableScope.push(true);
2646 2647
             } else {
2647 2648
                 executableScope.push(executableScope.top());
8  test/testtokenize.cpp
@@ -213,6 +213,7 @@ class TestTokenizer : public TestFixture {
213 213
         TEST_CASE(varid45); // #3466
214 214
         TEST_CASE(varid46); // struct varname
215 215
         TEST_CASE(varid47); // function parameters
  216
+        TEST_CASE(varid48); // #3785 - return (a*b)
216 217
         TEST_CASE(varid_cpp_keywords_in_c_code);
217 218
         TEST_CASE(varidFunctionCall1);
218 219
         TEST_CASE(varidFunctionCall2);
@@ -3241,6 +3242,13 @@ class TestTokenizer : public TestFixture {
3241 3242
                       tokenizeDebugListing(code, false, "test.cpp"));
3242 3243
     }
3243 3244
 
  3245
+    void varid48() {  // #3785 - return (a*b)
  3246
+        const std::string code("int X::f(int b) const { return(a*b); }");
  3247
+        ASSERT_EQUALS("\n\n##file 0\n"
  3248
+                      "1: int X :: f ( int b@1 ) const { return ( a * b@1 ) ; }\n",
  3249
+                      tokenizeDebugListing(code, false, "test.c"));
  3250
+    }
  3251
+
3244 3252
     void varid_cpp_keywords_in_c_code() {
3245 3253
         const char code[] = "void f() {\n"
3246 3254
                             "    delete d;\n"

0 notes on commit 8236cd4

Please sign in to comment.
Something went wrong with that request. Please try again.