From cb76061118d73f47749490633f71a84389738a60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 17 Oct 2009 19:31:14 +0200 Subject: [PATCH] unused struct member: bail out when casting --- src/checkother.cpp | 2 +- test/testunusedvar.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/checkother.cpp b/src/checkother.cpp index 7a21c2720..c444f04fb 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -621,7 +621,7 @@ void CheckOther::checkStructMemberUsage() } // Bail out if some data is casted to struct.. - const std::string s("( struct " + tok->next()->str() + " * ) & %var% ["); + const std::string s("( struct| " + tok->next()->str() + " * ) & %var% ["); if (Token::findmatch(tok, s.c_str())) structname = 0; } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index f259a0a34..3287db763 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -164,6 +164,18 @@ private: " struct AB *ab = (struct AB *)&buf[10];\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("struct AB\n" + "{\n" + " int a;\n" + " int b;\n" + "};\n" + "\n" + "void foo(char *buf)\n" + "{\n" + " struct AB *ab = (AB *)&buf[10];\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } };