From 7719e4309d322d5b7fea4ca89966f9557fad1b9d Mon Sep 17 00:00:00 2001 From: Achouv <50598660+Achouv@users.noreply.github.com> Date: Wed, 8 Apr 2020 18:09:20 +0200 Subject: [PATCH] avoid false positive unused static const struct member (#2598) --- lib/checkunusedvar.cpp | 2 ++ test/testunusedvar.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 59269cb18..bf8949eca 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1400,6 +1400,8 @@ void CheckUnusedVar::checkStructMemberUsage() // Check if the struct member variable is used anywhere in the file if (Token::findsimplematch(mTokenizer->tokens(), (". " + var.name()).c_str())) continue; + if (Token::findsimplematch(mTokenizer->tokens(), (":: " + var.name()).c_str())) + continue; unusedStructMemberError(var.nameToken(), scope.className, var.name(), scope.type == Scope::eUnion); } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index aa22cd7ad..c59de7e65 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -511,6 +511,17 @@ private: " ab.b = 0;\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (style) struct member 'AB::a' is never used.\n", errout.str()); + + checkStructMemberUsage("struct A\n" + "{\n" + " static const int a = 0;\n" + "};\n" + "\n" + "int foo()\n" + "{\n" + " return A::a;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void structmember_sizeof() {