diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp index aa0a2e223e708..33d308fe7bdb6 100644 --- a/clang/lib/Sema/CheckExprLifetime.cpp +++ b/clang/lib/Sema/CheckExprLifetime.cpp @@ -1261,12 +1261,12 @@ static void checkExprLifetimeImpl(Sema &SemaRef, if (pathContainsInit(Path)) return false; + auto *DRE = dyn_cast(L); // Suppress false positives for code like the one below: - // Ctor(unique_ptr up) : member(*up), member2(move(up)) {} - if (IsLocalGslOwner && pathOnlyHandlesGslPointer(Path)) + // Ctor(unique_ptr up) : pointer(up.get()), owner(move(up)) {} + if (DRE && isRecordWithAttr(DRE->getType())) return false; - auto *DRE = dyn_cast(L); auto *VD = DRE ? dyn_cast(DRE->getDecl()) : nullptr; if (!VD) { // A member was initialized to a local block. diff --git a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp index 688f55edfe84d..6a2af01ea5116 100644 --- a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp +++ b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp @@ -384,6 +384,19 @@ struct X { std::unique_ptr 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::iterator getIt(); std::vector getVec();