@@ -1188,7 +1188,7 @@ enum AnalysisResult {
11881188// Analyze cases where a GSLPointer is initialized or assigned from a
11891189// temporary owner object.
11901190static AnalysisResult analyzePathForGSLPointer (const IndirectLocalPath &Path,
1191- Local L) {
1191+ Local L, LifetimeKind LK ) {
11921192 if (!pathOnlyHandlesGslPointer (Path))
11931193 return NotGSLPointer;
11941194
@@ -1208,7 +1208,8 @@ static AnalysisResult analyzePathForGSLPointer(const IndirectLocalPath &Path,
12081208 // auto p2 = Temp().owner; // Here p2 is dangling.
12091209 if (const auto *FD = llvm::dyn_cast_or_null<FieldDecl>(E.D );
12101210 FD && !FD->getType ()->isReferenceType () &&
1211- isRecordWithAttr<OwnerAttr>(FD->getType ())) {
1211+ isRecordWithAttr<OwnerAttr>(FD->getType ()) &&
1212+ LK != LK_MemInitializer) {
12121213 return Report;
12131214 }
12141215 return Abandon;
@@ -1312,7 +1313,7 @@ checkExprLifetimeImpl(Sema &SemaRef, const InitializedEntity *InitEntity,
13121313 auto *MTE = dyn_cast<MaterializeTemporaryExpr>(L);
13131314
13141315 bool IsGslPtrValueFromGslTempOwner = true ;
1315- switch (analyzePathForGSLPointer (Path, L)) {
1316+ switch (analyzePathForGSLPointer (Path, L, LK )) {
13161317 case Abandon:
13171318 return false ;
13181319 case Skip:
@@ -1444,6 +1445,7 @@ checkExprLifetimeImpl(Sema &SemaRef, const InitializedEntity *InitEntity,
14441445 auto *DRE = dyn_cast<DeclRefExpr>(L);
14451446 // Suppress false positives for code like the one below:
14461447 // Ctor(unique_ptr<T> up) : pointer(up.get()), owner(move(up)) {}
1448+ // FIXME: move this logic to analyzePathForGSLPointer.
14471449 if (DRE && isRecordWithAttr<OwnerAttr>(DRE->getType ()))
14481450 return false ;
14491451
0 commit comments