Skip to content

Commit 69d669a

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

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,4 +629,8 @@ std::optional<std::string_view> test3(int i) {
629629
return sv; // fine
630630
}
631631

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

0 commit comments

Comments
 (0)