[C++] Failed assertion in `Parser::getParseListeners` : "vector iterators in range are from different containers", bug in `Parser::setTrimParseTree`
Author: Olivier11515Created Mar 11, 2026Updated Jul 3, 2026
Hello,
There is a bug at this line:
getParseListeners returns a std::vector (not a reference) so the iterators used in find() come from different containers, which is not allowed in C++. In debug this results in a failed assertion "vector iterators in range are from different containers".
The fix would be for example:
bool Parser::getTrimParseTree() {
const std::vector<tree::ParseTreeListener *> vec = getParseListeners();
return std::find(vec.begin(), vec.end(), &TrimToSizeListener::INSTANCE) != vec.end();
}Note that this code path is used when we use the setTrimParseTree method of Parser. As a result, setTrimParseTree may not behave the way it should.
Thanks!
Source: antlr/antlr4