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() {