Skip to content

Commit 6dc6a78

Browse files
committed
C++: Add a 'IteratorByPointer' class so pointers are always iterators.
1 parent d232283 commit 6dc6a78

File tree

1 file changed

+10
-0
lines changed
  • cpp/ql/lib/semmle/code/cpp/models/implementations

1 file changed

+10
-0
lines changed

cpp/ql/lib/semmle/code/cpp/models/implementations/Iterator.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ private class IteratorByTraits extends Iterator {
3434
IteratorByTraits() { exists(IteratorTraits it | it.getIteratorType() = this) }
3535
}
3636

37+
/**
38+
* The C++ standard includes an `std::iterator_traits` specialization for pointer types. When
39+
* this specialization is included in the database, a pointer type `T*` will be an instance
40+
* of the `IteratorByTraits` class. However, if the `T*` specialization is not in the database,
41+
* we need to explicitly include them with this class.
42+
*/
43+
private class IteratorByPointer extends Iterator instanceof PointerType {
44+
IteratorByPointer() { not this instanceof IteratorByTraits }
45+
}
46+
3747
/**
3848
* A type which has the typedefs expected for an iterator.
3949
*/

0 commit comments

Comments
 (0)