Changeset View
Changeset View
Standalone View
Standalone View
src/core/kfileitem.cpp
Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Line(s) | 1222 | { | |||
---|---|---|---|---|---|
1231 | return d->m_url == other.d->m_url; | 1231 | return d->m_url == other.d->m_url; | ||
1232 | } | 1232 | } | ||
1233 | 1233 | | |||
1234 | bool KFileItem::operator!=(const KFileItem &other) const | 1234 | bool KFileItem::operator!=(const KFileItem &other) const | ||
1235 | { | 1235 | { | ||
1236 | return !operator==(other); | 1236 | return !operator==(other); | ||
1237 | } | 1237 | } | ||
1238 | 1238 | | |||
1239 | bool KFileItem::operator<(const KFileItem &other) const | ||||
1240 | { | ||||
1241 | if (!d) { | ||||
dfaure: This isn't symmetric. operator< must have the property that a<b and b<a aren't both true, and… | |||||
this has to be otherwise (nullptr) < (nullptr). bruns: > If we decide that a null item is inferior to anything else, then we need
> if (!d) return… | |||||
1242 | return true; | ||||
1243 | } | ||||
1244 | if (!other.d) { | ||||
1245 | return false; | ||||
1246 | } | ||||
1247 | return d->m_url < other.d->m_url; | ||||
1248 | } | ||||
1249 | | ||||
1250 | bool KFileItem::operator<(const QUrl &other) const | ||||
1251 | { | ||||
1252 | if (!d) { | ||||
1253 | return true; | ||||
1254 | } | ||||
1255 | return d->m_url < other; | ||||
1256 | } | ||||
1257 | | ||||
1239 | KFileItem::operator QVariant() const | 1258 | KFileItem::operator QVariant() const | ||
1240 | { | 1259 | { | ||
1241 | return qVariantFromValue(*this); | 1260 | return qVariantFromValue(*this); | ||
1242 | } | 1261 | } | ||
1243 | 1262 | | |||
1244 | QString KFileItem::permissionsString() const | 1263 | QString KFileItem::permissionsString() const | ||
1245 | { | 1264 | { | ||
1246 | if (!d) { | 1265 | if (!d) { | ||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |
This isn't symmetric. operator< must have the property that a<b and b<a aren't both true, and that they are both false only if the items are equal.
If this is a valid item and other is null, then this code says that *this<other is false and other<*this is false.
Which would let some algorithms deduce that *this == other, which is completely wrong.
If we decide that a null item is inferior to anything else, then we need
(with newlines and braces of course).
This also calls for a corresponding unittest.