Selaa lähdekoodia

Fix a false positive warning when initializing members with gsl::Owners.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368501 91177308-0d34-0410-b5e6-96231b3b80d8
Gabor Horvath 6 vuotta sitten
vanhempi
commit
bc619fcd33
2 muutettua tiedostoa jossa 20 lisäystä ja 0 poistoa
  1. 5 0
      lib/Sema/SemaInit.cpp
  2. 15 0
      test/Sema/warn-lifetime-analysis-nocfg.cpp

+ 5 - 0
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) {

+ 15 - 0
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;
+};