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

valueflow.cpp: reduced some variable scopes/lifetimes #7076

Merged
merged 4 commits into from
Dec 15, 2024

Conversation

firewave
Copy link
Collaborator

@firewave firewave commented Dec 5, 2024

No description provided.

@firewave
Copy link
Collaborator Author

firewave commented Dec 5, 2024

This highlights some cases we could report via variableScope if we know the function call is pure or const and/or the type has no side effects. See https://trac.cppcheck.net/ticket/10117 and https://trac.cppcheck.net/ticket/11267.

@firewave firewave changed the title valiueflow.cpp: reduced some variable scopes valiueflow.cpp: reduced some variable scopes/lifetimes Dec 5, 2024
@chrchr-github chrchr-github changed the title valiueflow.cpp: reduced some variable scopes/lifetimes valueflow.cpp: reduced some variable scopes/lifetimes Dec 5, 2024
@@ -3699,8 +3699,11 @@ static void valueFlowSymbolicInfer(const SymbolDatabase& symboldatabase, const S
if (astIsFloat(tok->astOperand2(), false))
continue;

SymbolicInferModel leftModel{tok->astOperand1()};
std::vector<ValueFlow::Value> values = infer(leftModel, tok->str(), 0, tok->astOperand2()->values());
std::vector<ValueFlow::Value> values;
Copy link
Owner

Choose a reason for hiding this comment

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

I don't an opinion but we could also write:

 std::vector<ValueFlow::Value> values = [tok](){
        SymbolicInferModel leftModel{tok->astOperand1()};
        return infer(leftModel, tok->str(), 0, tok->astOperand2()->values());
 }();

Use the syntax you like..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do not find that more readable. I am also not sure fi that might introduce some overhead.

I mainly changed this because I was debugging the lifetime of the infer models at some point and was confused that two of them were alive at the same time.

Copy link
Owner

Choose a reason for hiding this comment

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

ok np

@firewave firewave merged commit 3a0f039 into danmar:main Dec 15, 2024
60 checks passed
@firewave firewave deleted the vf-scope branch December 15, 2024 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants