Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clang/lib/Sema/CheckExprLifetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,12 +1261,12 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
if (pathContainsInit(Path))
return false;

auto *DRE = dyn_cast<DeclRefExpr>(L);
// Suppress false positives for code like the one below:
// Ctor(unique_ptr<T> up) : member(*up), member2(move(up)) {}
if (IsLocalGslOwner && pathOnlyHandlesGslPointer(Path))
// Ctor(unique_ptr<T> up) : pointer(up.get()), owner(move(up)) {}
if (DRE && isRecordWithAttr<OwnerAttr>(DRE->getType()))
return false;

auto *DRE = dyn_cast<DeclRefExpr>(L);
auto *VD = DRE ? dyn_cast<VarDecl>(DRE->getDecl()) : nullptr;
if (!VD) {
// A member was initialized to a local block.
Expand Down
13 changes: 13 additions & 0 deletions clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,19 @@ struct X {
std::unique_ptr<int> pointer;
};

struct [[gsl::Owner]] XOwner {
int* get() const [[clang::lifetimebound]];
};
struct X2 {
// A common usage that moves the passing owner to the class.
// verify no warning on this case.
X2(XOwner owner) :
pointee(owner.get()),
owner(std::move(owner)) {}
int* pointee;
XOwner owner;
};

std::vector<int>::iterator getIt();
std::vector<int> getVec();

Expand Down
Loading