r368588 - Fix multiple lifetime warning messages for range based for loop
Gabor Horvath via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 12 09:19:39 PDT 2019
Author: xazax
Date: Mon Aug 12 09:19:39 2019
New Revision: 368588
URL: http://llvm.org/viewvc/llvm-project?rev=368588&view=rev
Log:
Fix multiple lifetime warning messages for range based for loop
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=368588&r1=368587&r2=368588&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Aug 12 09:19:39 2019
@@ -7070,8 +7070,11 @@ static SourceRange nextPathEntryRange(co
// 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(cons
return false;
}
- if (IsGslPtrInitWithGslTempOwner) {
+ if (IsGslPtrInitWithGslTempOwner && DiagLoc.isValid()) {
Diag(DiagLoc, diag::warn_dangling_lifetime_pointer) << DiagRange;
return false;
}
Modified: cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp?rev=368588&r1=368587&r2=368588&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp (original)
+++ cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp Mon Aug 12 09:19:39 2019
@@ -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;
More information about the cfe-commits
mailing list