From 650d58e3de2a9487edc36e97fb55cf0ebefb9f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 27 May 2009 19:38:26 +0200 Subject: [PATCH] Fix for ticket 337 ('scope can be limited' false positive with variables referenced by pointers) --- src/checkother.cpp | 5 +++++ test/testother.cpp | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/checkother.cpp b/src/checkother.cpp index 2fc7ee54e..306b7b11f 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -580,6 +580,11 @@ void CheckOther::CheckVariableScope_LookupVar(const Token *tok1, const char varn --parlevel; } + // Bail out if references are used + else if (Token::simpleMatch(tok, (std::string("& ") + varname).c_str())) + { + return; + } else if (tok->str() == varname) { diff --git a/test/testother.cpp b/test/testother.cpp index 5cc7adce4..46a0b967c 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -57,6 +57,7 @@ private: TEST_CASE(varScope1); TEST_CASE(varScope2); + TEST_CASE(varScope3); TEST_CASE(nullpointer1); TEST_CASE(nullpointer2); @@ -395,6 +396,21 @@ private: ASSERT_EQUALS(std::string(""), errout.str()); } + void varScope3() + { + varScope("void foo()\n" + "{\n" + " int i;\n" + " int *p = 0;\n" + " if (abc)\n" + " {\n" + " p = &i;\n" + " }\n" + " *p = 1;\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + } +