Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial fix for #12697 FN ignoredReturnValue with "pure" and "const" function attributes #6380

Merged
merged 1 commit into from
May 22, 2024

Conversation

chrchr-github
Copy link
Collaborator

No description provided.

@@ -278,7 +278,8 @@ void CheckFunctions::checkIgnoredReturnValue()
if ((!tok->function() || !Token::Match(tok->function()->retDef, "void %name%")) &&
tok->next()->astOperand1()) {
const Library::UseRetValType retvalTy = mSettings->library.getUseRetValType(tok);
const bool warn = (tok->function() && tok->function()->isAttributeNodiscard()) || // avoid duplicate warnings for resource-allocating functions
const bool warn = (tok->function() && (tok->function()->isAttributeNodiscard() || tok->function()->isAttributePure() || tok->function()->isAttributeConst())) ||
Copy link
Collaborator

@firewave firewave May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like we were not handling pure function at all previously. So we should also add a unit test for functions which have it specified in a library configuration.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change only affects user-declared functions. In the library, we have use-retval. Whether pure should imply use-retval when it is not specified is the topic of https://trac.cppcheck.net/ticket/12696

Copy link
Owner

@danmar danmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@chrchr-github chrchr-github merged commit ccfbc0c into danmar:main May 22, 2024
64 checks passed
@chrchr-github chrchr-github deleted the chr_Fix12697 branch May 22, 2024 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants