QtCore: Use Q_REQUIRED_RESULT in many more places

gcc doesn't yet warn when a non-POD return datatype is unused,
but clang does, at least.

This detected two bugs in qtbase due to the bad QDate method naming,
and will help application developers to avoid this trap too.

Change-Id: I106c1a32d2c6fc8d02f57beb7b61940605c80d76
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
David Faure 2014-03-13 21:27:05 +01:00 committed by The Qt Project
parent 4c1e15548a
commit b526e44a37
4 changed files with 55 additions and 55 deletions

View File

@ -247,9 +247,9 @@ public:
int count(const char *a) const; int count(const char *a) const;
int count(const QByteArray &a) const; int count(const QByteArray &a) const;
QByteArray left(int len) const; QByteArray left(int len) const Q_REQUIRED_RESULT;
QByteArray right(int len) const; QByteArray right(int len) const Q_REQUIRED_RESULT;
QByteArray mid(int index, int len = -1) const; QByteArray mid(int index, int len = -1) const Q_REQUIRED_RESULT;
bool startsWith(const QByteArray &a) const; bool startsWith(const QByteArray &a) const;
bool startsWith(char c) const; bool startsWith(char c) const;
@ -262,13 +262,13 @@ public:
void truncate(int pos); void truncate(int pos);
void chop(int n); void chop(int n);
QByteArray toLower() const; QByteArray toLower() const Q_REQUIRED_RESULT;
QByteArray toUpper() const; QByteArray toUpper() const Q_REQUIRED_RESULT;
QByteArray trimmed() const; QByteArray trimmed() const Q_REQUIRED_RESULT;
QByteArray simplified() const; QByteArray simplified() const Q_REQUIRED_RESULT;
QByteArray leftJustified(int width, char fill = ' ', bool truncate = false) const; QByteArray leftJustified(int width, char fill = ' ', bool truncate = false) const Q_REQUIRED_RESULT;
QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const; QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const Q_REQUIRED_RESULT;
QByteArray &prepend(char c); QByteArray &prepend(char c);
QByteArray &prepend(const char *s); QByteArray &prepend(const char *s);
@ -300,7 +300,7 @@ public:
QList<QByteArray> split(char sep) const; QList<QByteArray> split(char sep) const;
QByteArray repeated(int times) const; QByteArray repeated(int times) const Q_REQUIRED_RESULT;
#ifndef QT_NO_CAST_TO_ASCII #ifndef QT_NO_CAST_TO_ASCII
QT_ASCII_CAST_WARN QByteArray &append(const QString &s); QT_ASCII_CAST_WARN QByteArray &append(const QString &s);
@ -349,16 +349,16 @@ public:
QByteArray &setNum(double, char f = 'g', int prec = 6); QByteArray &setNum(double, char f = 'g', int prec = 6);
QByteArray &setRawData(const char *a, uint n); // ### Qt 6: use an int QByteArray &setRawData(const char *a, uint n); // ### Qt 6: use an int
static QByteArray number(int, int base = 10); static QByteArray number(int, int base = 10) Q_REQUIRED_RESULT;
static QByteArray number(uint, int base = 10); static QByteArray number(uint, int base = 10) Q_REQUIRED_RESULT;
static QByteArray number(qlonglong, int base = 10); static QByteArray number(qlonglong, int base = 10) Q_REQUIRED_RESULT;
static QByteArray number(qulonglong, int base = 10); static QByteArray number(qulonglong, int base = 10) Q_REQUIRED_RESULT;
static QByteArray number(double, char f = 'g', int prec = 6); static QByteArray number(double, char f = 'g', int prec = 6) Q_REQUIRED_RESULT;
static QByteArray fromRawData(const char *, int size); static QByteArray fromRawData(const char *, int size) Q_REQUIRED_RESULT;
static QByteArray fromBase64(const QByteArray &base64, Base64Options options); static QByteArray fromBase64(const QByteArray &base64, Base64Options options) Q_REQUIRED_RESULT;
static QByteArray fromBase64(const QByteArray &base64); // ### Qt6 merge with previous static QByteArray fromBase64(const QByteArray &base64) Q_REQUIRED_RESULT; // ### Qt6 merge with previous
static QByteArray fromHex(const QByteArray &hexEncoded); static QByteArray fromHex(const QByteArray &hexEncoded) Q_REQUIRED_RESULT;
static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%'); static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%') Q_REQUIRED_RESULT;
#if defined(Q_OS_MAC) || defined(Q_QDOC) #if defined(Q_OS_MAC) || defined(Q_QDOC)
static QByteArray fromCFData(CFDataRef data); static QByteArray fromCFData(CFDataRef data);

View File

@ -94,9 +94,9 @@ QT_DEPRECATED inline bool setYMD(int y, int m, int d)
void getDate(int *year, int *month, int *day); void getDate(int *year, int *month, int *day);
QDate addDays(qint64 days) const; QDate addDays(qint64 days) const Q_REQUIRED_RESULT;
QDate addMonths(int months) const; QDate addMonths(int months) const Q_REQUIRED_RESULT;
QDate addYears(int years) const; QDate addYears(int years) const Q_REQUIRED_RESULT;
qint64 daysTo(const QDate &) const; qint64 daysTo(const QDate &) const;
bool operator==(const QDate &other) const { return jd == other.jd; } bool operator==(const QDate &other) const { return jd == other.jd; }
@ -157,9 +157,9 @@ public:
#endif #endif
bool setHMS(int h, int m, int s, int ms = 0); bool setHMS(int h, int m, int s, int ms = 0);
QTime addSecs(int secs) const; QTime addSecs(int secs) const Q_REQUIRED_RESULT;
int secsTo(const QTime &) const; int secsTo(const QTime &) const;
QTime addMSecs(int ms) const; QTime addMSecs(int ms) const Q_REQUIRED_RESULT;
int msecsTo(const QTime &) const; int msecsTo(const QTime &) const;
bool operator==(const QTime &other) const { return mds == other.mds; } bool operator==(const QTime &other) const { return mds == other.mds; }
@ -251,11 +251,11 @@ public:
QString toString(Qt::DateFormat f = Qt::TextDate) const; QString toString(Qt::DateFormat f = Qt::TextDate) const;
QString toString(const QString &format) const; QString toString(const QString &format) const;
#endif #endif
QDateTime addDays(qint64 days) const; QDateTime addDays(qint64 days) const Q_REQUIRED_RESULT;
QDateTime addMonths(int months) const; QDateTime addMonths(int months) const Q_REQUIRED_RESULT;
QDateTime addYears(int years) const; QDateTime addYears(int years) const Q_REQUIRED_RESULT;
QDateTime addSecs(qint64 secs) const; QDateTime addSecs(qint64 secs) const Q_REQUIRED_RESULT;
QDateTime addMSecs(qint64 msecs) const; QDateTime addMSecs(qint64 msecs) const Q_REQUIRED_RESULT;
QDateTime toTimeSpec(Qt::TimeSpec spec) const; QDateTime toTimeSpec(Qt::TimeSpec spec) const;
inline QDateTime toLocalTime() const { return toTimeSpec(Qt::LocalTime); } inline QDateTime toLocalTime() const { return toTimeSpec(Qt::LocalTime); }

View File

@ -75,8 +75,8 @@ public:
inline void translate(const QPoint &p); inline void translate(const QPoint &p);
inline void translate(int dx, int dy); inline void translate(int dx, int dy);
Q_DECL_CONSTEXPR inline QLine translated(const QPoint &p) const; Q_DECL_CONSTEXPR inline QLine translated(const QPoint &p) const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QLine translated(int dx, int dy) const; Q_DECL_CONSTEXPR inline QLine translated(int dx, int dy) const Q_REQUIRED_RESULT;
inline void setP1(const QPoint &p1); inline void setP1(const QPoint &p1);
inline void setP2(const QPoint &p2); inline void setP2(const QPoint &p2);
@ -216,7 +216,7 @@ public:
Q_DECL_CONSTEXPR inline QLineF(qreal x1, qreal y1, qreal x2, qreal y2); Q_DECL_CONSTEXPR inline QLineF(qreal x1, qreal y1, qreal x2, qreal y2);
Q_DECL_CONSTEXPR inline QLineF(const QLine &line) : pt1(line.p1()), pt2(line.p2()) { } Q_DECL_CONSTEXPR inline QLineF(const QLine &line) : pt1(line.p1()), pt2(line.p2()) { }
static QLineF fromPolar(qreal length, qreal angle); static QLineF fromPolar(qreal length, qreal angle) Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR bool isNull() const; Q_DECL_CONSTEXPR bool isNull() const;
@ -240,8 +240,8 @@ public:
qreal angleTo(const QLineF &l) const; qreal angleTo(const QLineF &l) const;
QLineF unitVector() const; QLineF unitVector() const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QLineF normalVector() const; Q_DECL_CONSTEXPR inline QLineF normalVector() const Q_REQUIRED_RESULT;
// ### Qt 6: rename intersects() or intersection() and rename IntersectType IntersectionType // ### Qt 6: rename intersects() or intersection() and rename IntersectType IntersectionType
IntersectType intersect(const QLineF &l, QPointF *intersectionPoint) const; IntersectType intersect(const QLineF &l, QPointF *intersectionPoint) const;
@ -252,8 +252,8 @@ public:
inline void translate(const QPointF &p); inline void translate(const QPointF &p);
inline void translate(qreal dx, qreal dy); inline void translate(qreal dx, qreal dy);
Q_DECL_CONSTEXPR inline QLineF translated(const QPointF &p) const; Q_DECL_CONSTEXPR inline QLineF translated(const QPointF &p) const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QLineF translated(qreal dx, qreal dy) const; Q_DECL_CONSTEXPR inline QLineF translated(qreal dx, qreal dy) const Q_REQUIRED_RESULT;
inline void setP1(const QPointF &p1); inline void setP1(const QPointF &p1);
inline void setP2(const QPointF &p2); inline void setP2(const QPointF &p2);

View File

@ -68,7 +68,7 @@ public:
Q_DECL_CONSTEXPR inline int top() const; Q_DECL_CONSTEXPR inline int top() const;
Q_DECL_CONSTEXPR inline int right() const; Q_DECL_CONSTEXPR inline int right() const;
Q_DECL_CONSTEXPR inline int bottom() const; Q_DECL_CONSTEXPR inline int bottom() const;
QRect normalized() const; QRect normalized() const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline int x() const; Q_DECL_CONSTEXPR inline int x() const;
Q_DECL_CONSTEXPR inline int y() const; Q_DECL_CONSTEXPR inline int y() const;
@ -102,8 +102,8 @@ public:
inline void translate(int dx, int dy); inline void translate(int dx, int dy);
inline void translate(const QPoint &p); inline void translate(const QPoint &p);
Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const; Q_DECL_CONSTEXPR inline QRect translated(int dx, int dy) const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const; Q_DECL_CONSTEXPR inline QRect translated(const QPoint &p) const Q_REQUIRED_RESULT;
inline void moveTo(int x, int t); inline void moveTo(int x, int t);
inline void moveTo(const QPoint &p); inline void moveTo(const QPoint &p);
@ -115,7 +115,7 @@ public:
inline void getCoords(int *x1, int *y1, int *x2, int *y2) const; inline void getCoords(int *x1, int *y1, int *x2, int *y2) const;
inline void adjust(int x1, int y1, int x2, int y2); inline void adjust(int x1, int y1, int x2, int y2);
Q_DECL_CONSTEXPR inline QRect adjusted(int x1, int y1, int x2, int y2) const; Q_DECL_CONSTEXPR inline QRect adjusted(int x1, int y1, int x2, int y2) const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QSize size() const; Q_DECL_CONSTEXPR inline QSize size() const;
Q_DECL_CONSTEXPR inline int width() const; Q_DECL_CONSTEXPR inline int width() const;
@ -133,8 +133,8 @@ public:
bool contains(const QPoint &p, bool proper=false) const; bool contains(const QPoint &p, bool proper=false) const;
inline bool contains(int x, int y) const; inline bool contains(int x, int y) const;
inline bool contains(int x, int y, bool proper) const; inline bool contains(int x, int y, bool proper) const;
inline QRect united(const QRect &other) const; inline QRect united(const QRect &other) const Q_REQUIRED_RESULT;
inline QRect intersected(const QRect &other) const; inline QRect intersected(const QRect &other) const Q_REQUIRED_RESULT;
bool intersects(const QRect &r) const; bool intersects(const QRect &r) const;
Q_DECL_CONSTEXPR inline QRect marginsAdded(const QMargins &margins) const; Q_DECL_CONSTEXPR inline QRect marginsAdded(const QMargins &margins) const;
@ -143,8 +143,8 @@ public:
inline QRect &operator-=(const QMargins &margins); inline QRect &operator-=(const QMargins &margins);
#if QT_DEPRECATED_SINCE(5, 0) #if QT_DEPRECATED_SINCE(5, 0)
QT_DEPRECATED QRect unite(const QRect &r) const { return united(r); } QT_DEPRECATED QRect unite(const QRect &r) const Q_REQUIRED_RESULT { return united(r); }
QT_DEPRECATED QRect intersect(const QRect &r) const { return intersected(r); } QT_DEPRECATED QRect intersect(const QRect &r) const Q_REQUIRED_RESULT { return intersected(r); }
#endif #endif
friend Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &); friend Q_DECL_CONSTEXPR inline bool operator==(const QRect &, const QRect &);
@ -510,7 +510,7 @@ public:
Q_DECL_CONSTEXPR inline bool isNull() const; Q_DECL_CONSTEXPR inline bool isNull() const;
Q_DECL_CONSTEXPR inline bool isEmpty() const; Q_DECL_CONSTEXPR inline bool isEmpty() const;
Q_DECL_CONSTEXPR inline bool isValid() const; Q_DECL_CONSTEXPR inline bool isValid() const;
QRectF normalized() const; QRectF normalized() const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline qreal left() const { return xp; } Q_DECL_CONSTEXPR inline qreal left() const { return xp; }
Q_DECL_CONSTEXPR inline qreal top() const { return yp; } Q_DECL_CONSTEXPR inline qreal top() const { return yp; }
@ -550,8 +550,8 @@ public:
inline void translate(qreal dx, qreal dy); inline void translate(qreal dx, qreal dy);
inline void translate(const QPointF &p); inline void translate(const QPointF &p);
Q_DECL_CONSTEXPR inline QRectF translated(qreal dx, qreal dy) const; Q_DECL_CONSTEXPR inline QRectF translated(qreal dx, qreal dy) const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QRectF translated(const QPointF &p) const; Q_DECL_CONSTEXPR inline QRectF translated(const QPointF &p) const Q_REQUIRED_RESULT;
inline void moveTo(qreal x, qreal y); inline void moveTo(qreal x, qreal y);
inline void moveTo(const QPointF &p); inline void moveTo(const QPointF &p);
@ -563,7 +563,7 @@ public:
inline void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const; inline void getCoords(qreal *x1, qreal *y1, qreal *x2, qreal *y2) const;
inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2); inline void adjust(qreal x1, qreal y1, qreal x2, qreal y2);
Q_DECL_CONSTEXPR inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const; Q_DECL_CONSTEXPR inline QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const Q_REQUIRED_RESULT;
Q_DECL_CONSTEXPR inline QSizeF size() const; Q_DECL_CONSTEXPR inline QSizeF size() const;
Q_DECL_CONSTEXPR inline qreal width() const; Q_DECL_CONSTEXPR inline qreal width() const;
@ -580,8 +580,8 @@ public:
bool contains(const QRectF &r) const; bool contains(const QRectF &r) const;
bool contains(const QPointF &p) const; bool contains(const QPointF &p) const;
inline bool contains(qreal x, qreal y) const; inline bool contains(qreal x, qreal y) const;
inline QRectF united(const QRectF &other) const; inline QRectF united(const QRectF &other) const Q_REQUIRED_RESULT;
inline QRectF intersected(const QRectF &other) const; inline QRectF intersected(const QRectF &other) const Q_REQUIRED_RESULT;
bool intersects(const QRectF &r) const; bool intersects(const QRectF &r) const;
Q_DECL_CONSTEXPR inline QRectF marginsAdded(const QMarginsF &margins) const; Q_DECL_CONSTEXPR inline QRectF marginsAdded(const QMarginsF &margins) const;
@ -590,15 +590,15 @@ public:
inline QRectF &operator-=(const QMarginsF &margins); inline QRectF &operator-=(const QMarginsF &margins);
#if QT_DEPRECATED_SINCE(5, 0) #if QT_DEPRECATED_SINCE(5, 0)
QT_DEPRECATED QRectF unite(const QRectF &r) const { return united(r); } QT_DEPRECATED QRectF unite(const QRectF &r) const Q_REQUIRED_RESULT { return united(r); }
QT_DEPRECATED QRectF intersect(const QRectF &r) const { return intersected(r); } QT_DEPRECATED QRectF intersect(const QRectF &r) const Q_REQUIRED_RESULT { return intersected(r); }
#endif #endif
friend Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &); friend Q_DECL_CONSTEXPR inline bool operator==(const QRectF &, const QRectF &);
friend Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &); friend Q_DECL_CONSTEXPR inline bool operator!=(const QRectF &, const QRectF &);
Q_DECL_CONSTEXPR inline QRect toRect() const; Q_DECL_CONSTEXPR inline QRect toRect() const Q_REQUIRED_RESULT;
QRect toAlignedRect() const; QRect toAlignedRect() const Q_REQUIRED_RESULT;
private: private:
qreal xp; qreal xp;