[clang][Lifetimes] Fix false positive warning from BUG 49342

Differential Revision: https://reviews.llvm.org/D97605
This commit is contained in:
Gabor Horvath
2021-02-27 08:08:24 -08:00
parent 356cdabd3a
commit dd6738d93d
2 changed files with 17 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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>;
};
@@ -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.
}