Merge pull request #16557 from MathiasVP/fix-unique-pointer-query-fp

C++: Fix `cpp/use-of-unique-pointer-after-lifetime-ends` FP
This commit is contained in:
Mathias Vorreiter Pedersen
2024-05-22 15:09:54 +01:00
committed by GitHub
3 changed files with 14 additions and 0 deletions

View File

@@ -30,6 +30,8 @@ where
outlivesFullExpr(c) and
not c.isFromUninstantiatedTemplate(_) and
isUniquePointerDerefFunction(c.getTarget()) and
// Exclude cases where the pointer is implicitly converted to a non-pointer type
not c.getActualType() instanceof IntegralType and
isTemporary(c.getQualifier().getFullyConverted())
select c,
"The underlying unique pointer object is destroyed after the call to '" + c.getTarget() +

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The "Use of unique pointer after lifetime ends" query (`cpp/use-of-unique-pointer-after-lifetime-ends`) no longer reports an alert when the pointer is converted to a boolean

View File

@@ -203,4 +203,12 @@ void test2(bool b1, bool b2) {
auto s11 = b2 ? nullptr : sRefRef.get(); // GOOD
const S* s12;
s12 = sRefRef.get(); // GOOD
}
void test_convert_to_bool() {
bool b = get_unique_ptr().get(); // GOOD
if(get_unique_ptr().get()) { // GOOD
}
}