summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorGabor Horvath <xazax.hun@gmail.com>2019-08-10 00:32:29 +0000
committerGabor Horvath <xazax.hun@gmail.com>2019-08-10 00:32:29 +0000
commiteb563af70b54c9ef758393f863bdca00116be421 (patch)
tree6b7b6e0ae8fa3fed32182864041900ac61d2e58e /clang
parent1aaef90c2aab94407b047ee82b8ed9d3aecd532f (diff)
downloadbcm5719-llvm-eb563af70b54c9ef758393f863bdca00116be421.tar.gz
bcm5719-llvm-eb563af70b54c9ef758393f863bdca00116be421.zip
Fix a false positive warning when initializing members with gsl::Owners.
llvm-svn: 368501
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaInit.cpp5
-rw-r--r--clang/test/Sema/warn-lifetime-analysis-nocfg.cpp15
2 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index a54f5dbd750..9411c817451 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7217,6 +7217,11 @@ void Sema::checkInitializerLifetime(const InitializedEntity &Entity,
if (pathContainsInit(Path))
return false;
+ // Suppress false positives for code like the below:
+ // Ctor(unique_ptr<T> up) : member(*up), member2(move(up)) {}
+ if (IsLocalGslOwner && pathOnlyInitializesGslPointer(Path))
+ return false;
+
auto *DRE = dyn_cast<DeclRefExpr>(L);
auto *VD = DRE ? dyn_cast<VarDecl>(DRE->getDecl()) : nullptr;
if (!VD) {
diff --git a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
index efa54fe662b..c558901cf2e 100644
--- a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
+++ b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
@@ -120,6 +120,13 @@ void initLocalGslPtrWithTempOwner() {
}
namespace std {
+template<class T> struct remove_reference { typedef T type; };
+template<class T> struct remove_reference<T &> { typedef T type; };
+template<class T> struct remove_reference<T &&> { typedef T type; };
+
+template<class T>
+typename remove_reference<T>::type &&move(T &&t) noexcept;
+
template <typename T>
struct basic_iterator {
basic_iterator operator++();
@@ -153,6 +160,7 @@ struct basic_string {
template<typename T>
struct unique_ptr {
+ T &operator*();
T *get() const;
};
@@ -217,3 +225,10 @@ int &doNotFollowReferencesForLocalOwner() {
const char *trackThroughMultiplePointer() {
return std::basic_string_view<char>(std::basic_string<char>()).begin(); // expected-warning {{returning address of local temporary object}}
}
+
+struct X {
+ X(std::unique_ptr<int> up) : pointee(*up), pointer(std::move(up)) {}
+
+ int &pointee;
+ std::unique_ptr<int> pointer;
+};
OpenPOWER on IntegriCloud