diff options
| author | Gabor Horvath <xazax.hun@gmail.com> | 2019-08-11 14:39:42 +0000 |
|---|---|---|
| committer | Gabor Horvath <xazax.hun@gmail.com> | 2019-08-11 14:39:42 +0000 |
| commit | e812bf5530872e4b33c8f205da81acccc2a41413 (patch) | |
| tree | 576070da0679c54660d14947b6e50b8fa667640e /clang | |
| parent | 38c578854801fd9bda1eee44e6a8afcdc6ae6ce0 (diff) | |
| download | bcm5719-llvm-e812bf5530872e4b33c8f205da81acccc2a41413.tar.gz bcm5719-llvm-e812bf5530872e4b33c8f205da81acccc2a41413.zip | |
Properly detect temporary gsl::Owners through reference initialization chains.
llvm-svn: 368534
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 3 | ||||
| -rw-r--r-- | clang/test/Sema/warn-lifetime-analysis-nocfg.cpp | 10 |
2 files changed, 10 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 90b8d4a30dc..980696f4213 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -7104,7 +7104,8 @@ void Sema::checkInitializerLifetime(const InitializedEntity &Entity, SourceLocation DiagLoc = DiagRange.getBegin(); auto *MTE = dyn_cast<MaterializeTemporaryExpr>(L); - bool IsTempGslOwner = MTE && isRecordWithAttr<OwnerAttr>(MTE->getType()); + bool IsTempGslOwner = MTE && !MTE->getExtendingDecl() && + isRecordWithAttr<OwnerAttr>(MTE->getType()); bool IsLocalGslOwner = isa<DeclRefExpr>(L) && isRecordWithAttr<OwnerAttr>(L->getType()); diff --git a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp index 2e85a3f6f74..6503f412599 100644 --- a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp +++ b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp @@ -141,7 +141,7 @@ struct vector { typedef basic_iterator<T> iterator; iterator begin(); iterator end(); - T *data(); + const T *data() const; T &at(int n); }; @@ -235,8 +235,14 @@ struct X { }; std::vector<int>::iterator getIt(); +std::vector<int> getVec(); -const int &handleGslPtrInitsThroughReference(const std::vector<int> &v) { +const int &handleGslPtrInitsThroughReference() { const auto &it = getIt(); // Ok, it is lifetime extended. return *it; } + +void handleGslPtrInitsThroughReference2() { + const std::vector<int> &v = getVec(); + const int *val = v.data(); // Ok, it is lifetime extended. +} |

