Fix FP#11508#4774
Conversation
|
please check the CI failure. Seems there is assertion failure in the unit test. |
|
yeah, this is still work in progress - right now I am still trying to figure out how views should be propagated - as refs or differently. Thats why it was marked as work in progress but seems like @orbitcowboy changed it |
|
The problem is not how we propagate the views. Instead the checker should use different strategy when the lifetime is from a subfunction. |
|
Ah understood. Sorry. |
|
No problem :) @pfultz2 thanks for suggestion, I will work more on it in the weekend |
| else | ||
| { | ||
| master.lifetimeScope = ValueFlow::Value::LifetimeScope::Local; | ||
| } |
There was a problem hiding this comment.
The scope should be Local here. We only set SubFunction scope when the lifetime is passed from another function, like in valueFlowSubFunction. This function only infers lifetimes locally.
There was a problem hiding this comment.
I dont think the LifetimeScope needs to be changed. Instead we should only use local lifetimes when handling the indirection here(it should be v.isLocalLifetimeValue()):
Similar to the loop above when a dereference happens.
| "}\n" | ||
| "void f(std::string_view text) {" | ||
| "g(text.data());\n" | ||
| "}\n"); |
There was a problem hiding this comment.
The test cases should be indented.
There was a problem hiding this comment.
Hmm my reasoning was that if value has subfunction lifetime then any pointer/iterator to said in this scope should also has same lifetime. I will adjust it, thanks.
My current understanding is that views are treated as references - there is an issue that for references each of them has its own lifetime but view always uses lifetime of container it is 'viewing'. Lifetime of variable is done by comparing end of scopes where function is declared at and where it is used. Since those are 2 separate functions and not lambda FP is observed