Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.6
-
None
Description
I've found a couple of places where we have "library UB" (precondition violations).
I don't think there's anything that we need to do, strictly speaking, just something worth documenting.
1. In qjsonobject.cpp and qjsonparsers.cpp we use algorithms (std::lower_bound and std::stable_sort) on iterators that are not forward iterators. For instance
template<typename String> static qsizetype indexOf(const QExplicitlySharedDataPointer<QCborContainerPrivate> &o, String key, bool *keyExists) { const auto begin = QJsonPrivate::ConstKeyIterator(o->elements.constBegin()); const auto end = QJsonPrivate::ConstKeyIterator(o->elements.constEnd()); const auto it = std::lower_bound( begin, end, key, [&](const QJsonPrivate::ConstKeyIterator::value_type &e, const String &key) { return o->stringCompareElement(e.key(), key) < 0; }); *keyExists = (it != end) && o->stringEqualsElement((*it).key(), key); return it.it - begin.it; }
QJson iterators are only input, not forward, because dereferencing them gives back proxy types and not actual references, violating https://eel.is/c++draft/forward.iterators#1.3
if X is a mutable iterator, reference is a reference to T; if X is a constant iterator, reference is a reference to const T
2. In QLalr there's a Node type which has a std::set<Node> as a member. That's illegal because std::set requires its value type to be a complete type (only vector, list, forward_list have support for incomplete types).