diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-06-21 11:37:03 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-06-22 18:20:09 +0200 |
commit | 38cd3cb1261ee43e70cc5659ac72149a523995d3 (patch) | |
tree | d8223b466b9d19f778eb3f5b017a19533ed9c6de /tests/auto/corelib/global/qglobal | |
parent | 1a9ba8ee7d6d7cd624f5a299141bf4069a7cdeab (diff) |
Short live Q_NODISCARD_(CTOR_)X!
Wrappers around P1301 [[nodiscard("reason")]].
[ChangeLog][QtCore][Q_NODISCARD_X/Q_NODISCARD_CTOR_X] Added as
wrappers around C++20 [[nodiscard("reason")]].
Task-number: QTBUG-114767
Change-Id: Ie566d9c9d500ef632c7e243af97081f83506a752
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'tests/auto/corelib/global/qglobal')
-rw-r--r-- | tests/auto/corelib/global/qglobal/tst_qglobal.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 3d9759ff5b..e175db24b1 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -37,7 +37,7 @@ private slots: void qRoundDoubles(); void PRImacros(); void testqToUnderlying(); - void nodiscardConstructor(); + void nodiscard(); }; extern "C" { // functions in qglobal.c @@ -692,16 +692,19 @@ void tst_QGlobal::testqToUnderlying() QCOMPARE(qToUnderlying(EE2), 456UL); } -void tst_QGlobal::nodiscardConstructor() +void tst_QGlobal::nodiscard() { - // Syntax-only test, just to make sure that Q_NODISCARD_CTOR compiles + // Syntax-only test, just to make sure that the Q_NODISCARD_* compile // on all platforms. // Other code is just to silence all various compiler warnings about // unused private members or methods. class Test { public: - Q_NODISCARD_CTOR explicit Test(int val) : m_val(val) {} + Q_NODISCARD_CTOR_X("Why construct a Test instead of just passing the int through?") + explicit Test(int val) : m_val(val) {} + Q_NODISCARD_CTOR explicit Test(float val) : m_val(int(val)) {} + Q_NODISCARD_X("Why call get() if you don't use the returned value, hu?") // NOT idiomatic use! int get() const { return m_val; } private: @@ -710,6 +713,8 @@ void tst_QGlobal::nodiscardConstructor() Test t{42}; QCOMPARE(t.get(), 42); + Test t2{42.0f}; + QCOMPARE(t2.get(), 42); } QTEST_APPLESS_MAIN(tst_QGlobal) |