Fix #11546 FP danglingTemporaryLifetime with unknown member#5256
Fix #11546 FP danglingTemporaryLifetime with unknown member#5256chrchr-github merged 6 commits intocppcheck-opensource:mainfrom
Conversation
| ls.byVal(tok, tokenlist, errorLogger, settings); | ||
| }); | ||
| } else if (!isOwningVariables(constructor->nestedIn->varlist)) { | ||
| } else if (isOwningVariables(constructor->nestedIn->varlist, args)) { |
There was a problem hiding this comment.
Lifetimes should not be borrowed when using owning variables.
| })) | ||
| return false; | ||
| if (vt->isPrimitive()) | ||
| if (vt->pointer > 0) |
There was a problem hiding this comment.
If its a pointer then its not an owning variable.
| if (vt->pointer > 0) | ||
| if (std::none_of(args.begin(), args.end(), [vt](const Token* arg) { | ||
| return arg->valueType() && arg->valueType()->type == vt->type; | ||
| })) |
There was a problem hiding this comment.
I think this check can only be done with pointers. Another user class or container view could still borrow the lifetime.
|
What is |
|
Pointers and references(except shared_ptr and unique_ptr) borrow the lifetime it does not own it. |
|
Shouldn't the function then be called |
Originally, the function was the opposite which is why it was named |
| const ValueType* vt = var.valueType(); | ||
| if (vt) { | ||
| if (vt->pointer > 0) | ||
| if (std::none_of(args.begin(), args.end(), [vt](const Token* arg) { |
There was a problem hiding this comment.
This should be if (vt->pointer > 0 && std::none_of(args.begin(), args.end(), ...)). I haven't tested on this PR, but it looks like without this check it could lead to FPs in cases like this:
struct A {
explicit A(int& i) {
data = std::span<int>{&i, 1};
}
void foo() const {
for(auto& i:data) i++;
}
std::span<int> data;
};
int f() {
int i = -1;
A a{i};
i = 0;
a.foo();
return 1 / i;
}There was a problem hiding this comment.
There already is a FP for this, and if (vt->pointer > 0 ... does not prevent it.
|
Any more feedback? |
No description provided.