From dd914c0089df121055624aeeb54674a14720deb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 4 Jan 2009 08:16:07 +0000 Subject: [PATCH] Function usage : Fixed false positives for inline structs --- checkother.cpp | 8 ++++++++ testunusedvar.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/checkother.cpp b/checkother.cpp index 109608b83..6d30a6671 100644 --- a/checkother.cpp +++ b/checkother.cpp @@ -842,6 +842,14 @@ void CheckOther::functionVariableUsage() if ( indentlevel <= 0 ) break; } + else if ( Token::simpleMatch(tok, "struct {") ) + { + while ( tok && tok->str() != "}" ) + tok = tok->next(); + if ( tok ) + continue; + break; + } if ( Token::Match(tok, "[;{}] bool|char|short|int|long|float|double %var% ;|=") ) varUsage[ tok->strAt(2) ] = USAGE_DECLARE; diff --git a/testunusedvar.cpp b/testunusedvar.cpp index 310505113..ae66b8b75 100644 --- a/testunusedvar.cpp +++ b/testunusedvar.cpp @@ -62,6 +62,7 @@ private: TEST_CASE( localvar3 ); TEST_CASE( localvar4 ); TEST_CASE( localvar5 ); + TEST_CASE( localvar6 ); } void structmember1() @@ -186,6 +187,17 @@ private: "}\n" ); ASSERT_EQUALS( std::string(""), errout.str() ); } + + void localvar6() + { + functionVariableUsage( "void foo()\n" + "{\n" + " static const struct{ int x, y, w, h; } bounds = {1,2,3,4};\n" + " return bounds.x + bounds.y + bounds.w + bounds.h;\n" + "}\n" ); + ASSERT_EQUALS( std::string(""), errout.str() ); + } + }; REGISTER_TEST( TestUnusedVar )