r368501 - Fix a false positive warning when initializing members with gsl::Owners.
Gabor Horvath via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 9 17:32:29 PDT 2019
Author: xazax
Date: Fri Aug 9 17:32:29 2019
New Revision: 368501
URL: http://llvm.org/viewvc/llvm-project?rev=368501&view=rev
Log:
Fix a false positive warning when initializing members with gsl::Owners.
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=368501&r1=368500&r2=368501&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Aug 9 17:32:29 2019
@@ -7217,6 +7217,11 @@ void Sema::checkInitializerLifetime(cons
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) {
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=368501&r1=368500&r2=368501&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp (original)
+++ cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp Fri Aug 9 17:32:29 2019
@@ -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;
+};
More information about the cfe-commits
mailing list