File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -278,7 +278,8 @@ void CheckFunctions::checkIgnoredReturnValue()
278278 if ((!tok->function () || !Token::Match (tok->function ()->retDef , " void %name%" )) &&
279279 tok->next ()->astOperand1 ()) {
280280 const Library::UseRetValType retvalTy = mSettings ->library .getUseRetValType (tok);
281- const bool warn = (tok->function () && tok->function ()->isAttributeNodiscard ()) || // avoid duplicate warnings for resource-allocating functions
281+ const bool warn = (tok->function () && (tok->function ()->isAttributeNodiscard () || tok->function ()->isAttributePure () || tok->function ()->isAttributeConst ())) ||
282+ // avoid duplicate warnings for resource-allocating functions
282283 (retvalTy == Library::UseRetValType::DEFAULT && mSettings ->library .getAllocFuncInfo (tok) == nullptr );
283284 if (mSettings ->severity .isEnabled (Severity::warning) && warn)
284285 ignoredReturnValueError (tok, tok->next ()->astOperand1 ()->expressionString ());
Original file line number Diff line number Diff line change @@ -1434,6 +1434,16 @@ class TestFunctions : public TestFixture {
14341434 " delete *v.begin();\n "
14351435 " }\n " );
14361436 ASSERT_EQUALS (" " , errout_str ());
1437+
1438+ check (" int __attribute__((pure)) p_foo(int);\n " // #12697
1439+ " int __attribute__((const)) c_foo(int);\n "
1440+ " void f() {\n "
1441+ " p_foo(0);\n "
1442+ " c_foo(0);\n "
1443+ " }\n " );
1444+ ASSERT_EQUALS (" [test.cpp:4]: (warning) Return value of function p_foo() is not used.\n "
1445+ " [test.cpp:5]: (warning) Return value of function c_foo() is not used.\n " ,
1446+ errout_str ());
14371447 }
14381448
14391449 void checkIgnoredErrorCode () {
You can’t perform that action at this time.
0 commit comments