Skip to content

Commit 15728aa

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

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
@@ -663,4 +663,8 @@ std::optional<std::string_view> test3(int i) {
663663
return sv; // fine
664664
}
665665

666+
std::optional<int*> test4(int a) {
667+
return std::make_optional(nullptr); // fine
668+
}
669+
666670
} // namespace GH100526

0 commit comments

Comments
 (0)