Skip to content

Commit edea044

Browse files
committed
Fix the false positive for make_optional(nullptr);
We should also consider isNullPtrType as the pointer type.
1 parent d109632 commit edea044

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/Sema/CheckExprLifetime.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ static bool isContainerOfPointer(const RecordDecl *Container) {
277277
const auto &TAs = CTSD->getTemplateArgs();
278278
return TAs.size() > 0 && TAs[0].getKind() == TemplateArgument::Type &&
279279
(isRecordWithAttr<PointerAttr>(TAs[0].getAsType()) ||
280-
TAs[0].getAsType()->isPointerType());
280+
TAs[0].getAsType()->isPointerType() ||
281+
TAs[0].getAsType()->isNullPtrType());
281282
}
282283
return false;
283284
}

clang/test/Sema/warn-lifetime-analysis-nocfg.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,4 +629,9 @@ std::optional<std::string_view> test3(int i) {
629629
return sv; // fine
630630
}
631631

632+
std::optional<int*> test4(int a) {
633+
if (a)
634+
return std::make_optional(nullptr); // fine
635+
}
636+
632637
} // namespace GH100526

0 commit comments

Comments
 (0)