Skip to content

Commit 55f9462

Browse files
committed
Address review comments.
1 parent b2756de commit 55f9462

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

clang/lib/Sema/CheckExprLifetime.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,15 @@ static bool isContainerOfPointer(const RecordDecl *Container) {
290290
return false;
291291
}
292292
static bool isContainerOfOwner(const RecordDecl *Container) {
293-
if (const auto *CTSD =
294-
dyn_cast_if_present<ClassTemplateSpecializationDecl>(Container)) {
295-
if (!CTSD->hasAttr<OwnerAttr>()) // Container must be a GSL owner type.
296-
return false;
297-
const auto &TAs = CTSD->getTemplateArgs();
298-
return TAs.size() > 0 && TAs[0].getKind() == TemplateArgument::Type &&
299-
isRecordWithAttr<OwnerAttr>(TAs[0].getAsType());
300-
}
301-
return false;
293+
const auto *CTSD =
294+
dyn_cast_if_present<ClassTemplateSpecializationDecl>(Container);
295+
if (!CTSD)
296+
return false;
297+
if (!CTSD->hasAttr<OwnerAttr>()) // Container must be a GSL owner type.
298+
return false;
299+
const auto &TAs = CTSD->getTemplateArgs();
300+
return TAs.size() > 0 && TAs[0].getKind() == TemplateArgument::Type &&
301+
isRecordWithAttr<OwnerAttr>(TAs[0].getAsType());
302302
}
303303

304304
// Returns true if the given Record is `std::initializer_list<pointer>`.
@@ -383,7 +383,7 @@ static bool isCopyLikeConstructor(const CXXConstructorDecl *Ctor) {
383383
if (!ParamRefType)
384384
return false;
385385

386-
// Check if the first parameter type "Owner<U>".
386+
// Check if the first parameter type is "Owner<U>".
387387
if (const auto *TST =
388388
ParamRefType->getPointeeType()->getAs<TemplateSpecializationType>())
389389
return TST->getTemplateName()

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,4 +769,11 @@ const int& test12(Span<int> a) {
769769
return a.getFieldNoLB(); // OK.
770770
}
771771

772+
void test13() {
773+
// FIXME: RHS is Owner<Pointer>, we skip this case to avoid false positives.
774+
std::optional<Span<int*>> abc = std::vector<int*>{};
775+
776+
std::optional<Span<int>> t = std::vector<int> {}; // expected-warning {{object backing the pointer will be destroyed}}
777+
}
778+
772779
} // namespace GH100526

0 commit comments

Comments
 (0)