From 4a64e205929b39f3daf5f249a1b5253a25c9efb3 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 17 Aug 2022 19:45:46 +0200 Subject: [PATCH] unusedScopedObject: Don't warn for void statements (#4370) * Fix unusedScopedObject FPs * Simplify * Simplify * Fix test * Don't warn for void statements * Format --- lib/checkother.cpp | 3 ++- test/testother.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index f6ad444b3..d75f33f03 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2062,7 +2062,8 @@ void CheckOther::checkMisusedScopedObject() && Token::Match(tok->linkAt(2), ")|} ; !!}") && (!tok->next()->function() || // is not a function on this scope tok->next()->function()->isConstructor()) // or is function in this scope and it's a ctor - && !Token::simpleMatch(tok->tokAt(2)->astParent(), ";")) { // for loop condition + && !Token::simpleMatch(tok->tokAt(2)->astParent(), ";") // for loop condition + && tok->next()->str() != "void") { if (const Token* arg = tok->tokAt(2)->astOperand2()) { if (!isConstStatement(arg, mTokenizer->isCPP())) continue; diff --git a/test/testother.cpp b/test/testother.cpp index c8be58e41..ed3ed8547 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5060,6 +5060,12 @@ private: " float (*p);\n" "}\n", "test.cpp"); ASSERT_EQUALS("", errout.str()); + + check("int f(int i) {\n" + " void();\n" + " return i;\n" + "}\n", "test.cpp"); + ASSERT_EQUALS("", errout.str()); } void trac2084() {