@@ -1008,7 +1008,19 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
1008
1008
return true ;
1009
1009
}
1010
1010
}
1011
+ if (AEntity) {
1012
+ if (!MTE)
1013
+ return false ;
1014
+ assert (shouldLifetimeExtendThroughPath (Path) ==
1015
+ PathLifetimeKind::NoExtend &&
1016
+ " No lifetime extension for assignments" );
1017
+ if (!pathContainsInit (Path))
1018
+ SemaRef.Diag (DiagLoc, diag::warn_dangling_pointer_assignment)
1019
+ << AEntity->LHS << DiagRange;
1020
+ return false ;
1021
+ }
1011
1022
1023
+ assert (InitEntity && " only for initialization" );
1012
1024
switch (LK) {
1013
1025
case LK_FullExpression:
1014
1026
llvm_unreachable (" already handled this" );
@@ -1031,8 +1043,6 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
1031
1043
1032
1044
switch (shouldLifetimeExtendThroughPath (Path)) {
1033
1045
case PathLifetimeKind::Extend:
1034
- assert (InitEntity && " Lifetime extension should happen only for "
1035
- " initialization and not assignment" );
1036
1046
// Update the storage duration of the materialized temporary.
1037
1047
// FIXME: Rebuild the expression instead of mutating it.
1038
1048
MTE->setExtendingDecl (ExtendingEntity->getDecl (),
@@ -1041,8 +1051,6 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
1041
1051
return true ;
1042
1052
1043
1053
case PathLifetimeKind::ShouldExtend:
1044
- assert (InitEntity && " Lifetime extension should happen only for "
1045
- " initialization and not assignment" );
1046
1054
// We're supposed to lifetime-extend the temporary along this path (per
1047
1055
// the resolution of DR1815), but we don't support that yet.
1048
1056
//
@@ -1060,23 +1068,16 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
1060
1068
if (pathContainsInit (Path))
1061
1069
return false ;
1062
1070
1063
- if (InitEntity) {
1064
- SemaRef.Diag (DiagLoc, diag::warn_dangling_variable)
1065
- << RK << !InitEntity->getParent ()
1066
- << ExtendingEntity->getDecl ()->isImplicit ()
1067
- << ExtendingEntity->getDecl () << Init->isGLValue () << DiagRange;
1068
- } else {
1069
- SemaRef.Diag (DiagLoc, diag::warn_dangling_pointer_assignment)
1070
- << AEntity->LHS << DiagRange;
1071
- }
1071
+ SemaRef.Diag (DiagLoc, diag::warn_dangling_variable)
1072
+ << RK << !InitEntity->getParent ()
1073
+ << ExtendingEntity->getDecl ()->isImplicit ()
1074
+ << ExtendingEntity->getDecl () << Init->isGLValue () << DiagRange;
1072
1075
break ;
1073
1076
}
1074
1077
break ;
1075
1078
}
1076
1079
1077
1080
case LK_MemInitializer: {
1078
- assert (InitEntity && " Expect only on initializing the entity" );
1079
-
1080
1081
if (MTE) {
1081
1082
// Under C++ DR1696, if a mem-initializer (or a default member
1082
1083
// initializer used by the absence of one) would lifetime-extend a
@@ -1151,7 +1152,6 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
1151
1152
}
1152
1153
1153
1154
case LK_New:
1154
- assert (InitEntity && " Expect only on initializing the entity" );
1155
1155
if (isa<MaterializeTemporaryExpr>(L)) {
1156
1156
if (IsGslPtrInitWithGslTempOwner)
1157
1157
SemaRef.Diag (DiagLoc, diag::warn_dangling_lifetime_pointer)
@@ -1169,7 +1169,6 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
1169
1169
1170
1170
case LK_Return:
1171
1171
case LK_StmtExprResult:
1172
- assert (InitEntity && " Expect only on initializing the entity" );
1173
1172
if (auto *DRE = dyn_cast<DeclRefExpr>(L)) {
1174
1173
// We can't determine if the local variable outlives the statement
1175
1174
// expression.
0 commit comments