Skip to content

Commit

Permalink
[clang][Lifetimes] Fix false positive warning from BUG 49342
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D97605
  • Loading branch information
Xazax-hun committed Feb 27, 2021
1 parent 356cdab commit dd6738d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/lib/Sema/SemaInit.cpp
Expand Up @@ -7521,6 +7521,8 @@ static bool pathOnlyInitializesGslPointer(IndirectLocalPath &Path) {
continue;
if (It->Kind == IndirectLocalPathEntry::AddressOf)
continue;
if (It->Kind == IndirectLocalPathEntry::LifetimeBoundCall)
continue;
return It->Kind == IndirectLocalPathEntry::GslPointerInit ||
It->Kind == IndirectLocalPathEntry::GslReferenceInit;
}
Expand Down
15 changes: 15 additions & 0 deletions clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
Expand Up @@ -171,12 +171,22 @@ struct basic_string_view {
const T *begin() const;
};

template<class _Mystr> struct iter {
iter& operator-=(int);

iter operator-(int _Off) const {
iter _Tmp = *this;
return _Tmp -= _Off;
}
};

template<typename T>
struct basic_string {
basic_string();
basic_string(const T *);
const T *c_str() const;
operator basic_string_view<T> () const;
using const_iterator = iter<T>;
};


Expand Down Expand Up @@ -455,3 +465,8 @@ std::vector<int>::iterator noFalsePositiveWithVectorOfPointers() {
std::vector<std::vector<int>::iterator> iters;
return iters.at(0);
}

void testForBug49342()
{
auto it = std::iter<char>{} - 2; // Used to be false positive.
}

0 comments on commit dd6738d

Please sign in to comment.