From e4291a59667f681f24c2f6725e08fd952a34ee4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 17 Sep 2009 21:05:12 +0200 Subject: [PATCH] Fixed #676 (The scope of variable can actually not be limited) --- src/checkother.cpp | 2 +- test/testother.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/checkother.cpp b/src/checkother.cpp index 036375b48..321300503 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -594,7 +594,7 @@ void CheckOther::checkVariableScope() continue; // Variable declaration? - if (Token::Match(tok1, "%type% %var% ; %var% = %any% ;")) + if (Token::Match(tok1, "%type% %var% ; %var% = %num% ;")) { // Tokenizer modify "int i = 0;" to "int i; i = 0;", // so to handle this situation we just skip diff --git a/test/testother.cpp b/test/testother.cpp index 4b79e8a15..4a8e41ecd 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -58,6 +58,7 @@ private: TEST_CASE(varScope3); TEST_CASE(varScope4); TEST_CASE(varScope5); + TEST_CASE(varScope6); TEST_CASE(nullpointer1); TEST_CASE(nullpointer2); @@ -495,6 +496,21 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable i can be limited\n", errout.str()); } + void varScope6() + { + varScope("void f(int x)\n" + "{\n" + " int i = x;\n" + " if (a) {\n" + " x++;\n" + " }\n" + " if (b) {\n" + " c(i);\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void checkNullPointer(const char code[])