summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaInit.cpp7
-rw-r--r--clang/test/Sema/warn-lifetime-analysis-nocfg.cpp7
2 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2be4e897c8e..17cfd129324 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -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;
}
diff --git a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
index 6503f412599..696c04b237d 100644
--- a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
+++ b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
@@ -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;
OpenPOWER on IntegriCloud