[analyzer] Add system header simulator a symmetric random access iterator operator+

Summary:
Random access iterators must handle operator+, where the iterator is on the
RHS. The system header simulator library is extended with these operators.

Reviewers: Szelethus

Subscribers: whisperity, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, Charusso, steakhal, martong, ASDenysPetrov, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83226
This commit is contained in:
Endre Fülöp 2020-07-06 16:25:57 +02:00
parent 23c9534515
commit fd02a86260
2 changed files with 11 additions and 1 deletions

View File

@ -60,6 +60,11 @@ template <typename T, typename Ptr, typename Ref> struct __vector_iterator {
__vector_iterator<T, Ptr, Ref> operator+(difference_type n) {
return ptr + n;
}
friend __vector_iterator<T, Ptr, Ref> operator+(
difference_type n,
const __vector_iterator<T, Ptr, Ref> &iter) {
return n + iter.ptr;
}
__vector_iterator<T, Ptr, Ref> operator-(difference_type n) {
return ptr - n;
}
@ -118,6 +123,11 @@ template <typename T, typename Ptr, typename Ref> struct __deque_iterator {
__deque_iterator<T, Ptr, Ref> operator+(difference_type n) {
return ptr + n;
}
friend __deque_iterator<T, Ptr, Ref> operator+(
difference_type n,
const __deque_iterator<T, Ptr, Ref> &iter) {
return n + iter.ptr;
}
__deque_iterator<T, Ptr, Ref> operator-(difference_type n) {
return ptr - n;
}

View File

@ -19,6 +19,6 @@ class C {
void testCopyNull(C *I, C *E) {
std::copy(I, E, (C *)0);
#ifndef SUPPRESSED
// expected-warning@../Inputs/system-header-simulator-cxx.h:699 {{Called C++ object pointer is null}}
// expected-warning@../Inputs/system-header-simulator-cxx.h:709 {{Called C++ object pointer is null}}
#endif
}