From 141af7cc87352d14aa921f5c05ddacf94c3636d4 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Fri, 26 Apr 2024 18:11:44 +0100 Subject: [PATCH] C++: Subclasses for both 'begin' and 'end'. --- .../cpp/models/implementations/Iterator.qll | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/models/implementations/Iterator.qll b/cpp/ql/lib/semmle/code/cpp/models/implementations/Iterator.qll index 8e527c7e694..89658000c8a 100644 --- a/cpp/ql/lib/semmle/code/cpp/models/implementations/Iterator.qll +++ b/cpp/ql/lib/semmle/code/cpp/models/implementations/Iterator.qll @@ -579,17 +579,34 @@ private class IteratorAssignmentMemberOperatorModel extends IteratorAssignmentMe override predicate parameterEscapesOnlyViaReturn(int index) { index = -1 } } +/** + * A `begin` member function, or a related function, that returns an iterator. + */ +class BeginFunction extends MemberFunction { + BeginFunction() { + this.hasName(["begin", "cbegin", "rbegin", "crbegin", "before_begin", "cbefore_begin"]) and + this.getType().getUnspecifiedType() instanceof Iterator + } +} + +/** + * An `end` member function, or a related function, that returns an iterator. + */ +class EndFunction extends MemberFunction { + EndFunction() { + this.hasName(["end", "cend", "rend", "crend"]) and + this.getType().getUnspecifiedType() instanceof Iterator + } +} + /** * A `begin` or `end` member function, or a related member function, that * returns an iterator. */ class BeginOrEndFunction extends MemberFunction { BeginOrEndFunction() { - this.hasName([ - "begin", "cbegin", "rbegin", "crbegin", "end", "cend", "rend", "crend", "before_begin", - "cbefore_begin" - ]) and - this.getType().getUnspecifiedType() instanceof Iterator + this instanceof BeginFunction or + this instanceof EndFunction } }