forked from OSchip/llvm-project
Fix multiple lifetime warning messages for range based for loop
llvm-svn: 368588
This commit is contained in:
parent
83bbfaa5e4
commit
c6802b231f
|
@ -7070,8 +7070,11 @@ static SourceRange nextPathEntryRange(const IndirectLocalPath &Path, unsigned I,
|
|||
// supporting lifetime extension.
|
||||
break;
|
||||
|
||||
case IndirectLocalPathEntry::DefaultInit:
|
||||
case IndirectLocalPathEntry::VarInit:
|
||||
if (cast<VarDecl>(Path[I].D)->isImplicit())
|
||||
return SourceRange();
|
||||
LLVM_FALLTHROUGH;
|
||||
case IndirectLocalPathEntry::DefaultInit:
|
||||
return Path[I].E->getSourceRange();
|
||||
}
|
||||
}
|
||||
|
@ -7138,7 +7141,7 @@ void Sema::checkInitializerLifetime(const InitializedEntity &Entity,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (IsGslPtrInitWithGslTempOwner) {
|
||||
if (IsGslPtrInitWithGslTempOwner && DiagLoc.isValid()) {
|
||||
Diag(DiagLoc, diag::warn_dangling_lifetime_pointer) << DiagRange;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -209,6 +209,13 @@ void danglingReferenceFromTempOwner() {
|
|||
std::vector<int> getTempVec();
|
||||
std::optional<std::vector<int>> getTempOptVec();
|
||||
|
||||
void testLoops() {
|
||||
for (auto i : getTempVec()) // ok
|
||||
;
|
||||
for (auto i : *getTempOptVec()) // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}}
|
||||
;
|
||||
}
|
||||
|
||||
int &usedToBeFalsePositive(std::vector<int> &v) {
|
||||
std::vector<int>::iterator it = v.begin();
|
||||
int& value = *it;
|
||||
|
|
Loading…
Reference in New Issue