From: Gabor Horvath Date: Sat, 10 Aug 2019 00:32:29 +0000 (+0000) Subject: Fix a false positive warning when initializing members with gsl::Owners. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc619fcd33a27e82817954cd708cc7724c09b155;p=clang 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 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index a54f5dbd75..9411c81745 100644 --- a/lib/Sema/SemaInit.cpp +++ b/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 up) : member(*up), member2(move(up)) {} + if (IsLocalGslOwner && pathOnlyInitializesGslPointer(Path)) + return false; + auto *DRE = dyn_cast(L); auto *VD = DRE ? dyn_cast(DRE->getDecl()) : nullptr; if (!VD) { diff --git a/test/Sema/warn-lifetime-analysis-nocfg.cpp b/test/Sema/warn-lifetime-analysis-nocfg.cpp index efa54fe662..c558901cf2 100644 --- a/test/Sema/warn-lifetime-analysis-nocfg.cpp +++ b/test/Sema/warn-lifetime-analysis-nocfg.cpp @@ -120,6 +120,13 @@ void initLocalGslPtrWithTempOwner() { } namespace std { +template struct remove_reference { typedef T type; }; +template struct remove_reference { typedef T type; }; +template struct remove_reference { typedef T type; }; + +template +typename remove_reference::type &&move(T &&t) noexcept; + template struct basic_iterator { basic_iterator operator++(); @@ -153,6 +160,7 @@ struct basic_string { template struct unique_ptr { + T &operator*(); T *get() const; }; @@ -217,3 +225,10 @@ int &doNotFollowReferencesForLocalOwner() { const char *trackThroughMultiplePointer() { return std::basic_string_view(std::basic_string()).begin(); // expected-warning {{returning address of local temporary object}} } + +struct X { + X(std::unique_ptr up) : pointee(*up), pointer(std::move(up)) {} + + int &pointee; + std::unique_ptr pointer; +};