qt5base-lts/tests/auto/corelib/global
Ivan Solovev 959800f6de Short live Q_NODISCARD_CTOR
[ChangeLog][QtCore] Introduced Q_NODISCARD_CTOR which resolves to
[[nodiscard]] attribute for constructors on compilers that support
it, and does nothing on other compilers.

Using [[nodiscard]] attribute on a constructor is a C++20 feature,
however in practice it is supported on most of the compilers that
we use in Qt 6. Clang generates a [-Wunused-value] warning, GCC
and MinGW generate a [-Wunused-result] warnings, and MSVC
generates a C4834 warning.
However, there are some exceptions.

The Integrity compiler provides the following warning:
 "tst_qglobal.cpp", line 699: warning #3435-D:
           the "nodiscard" attribute doesn't apply to constructors,
           destructors, or routines with void return type
           [[nodiscard]] explicit Test(int val) : m_val(val) {}

The QNX compiler (QCC 8.3.0) and GCC 9.3.1 on OpenSUSE generate
the [-Wattributes] warning:
 tst_qglobal.cpp: In member function
   'void tst_QGlobal::nodiscardConstructor()':
 tst_qglobal.cpp:699:44: warning: 'nodiscard' attribute applied to
   'tst_QGlobal::nodiscardConstructor()::Test::Test(int)' with void
    return type [-Wattributes]
          [[nodiscard]] explicit Test(int val) : m_val(val) {}

These warnings will lead to build failures when compiled with
-warnings-are-errors flag, so for these compilers the macro
does not do anything.

An attempt to use __attribute__((__warn_unused_result__)) was
also unsuccessful on these compilers, so this patch goes for
an easy solution, and simply checks
 __has_cpp_attribute(nodiscard) >= 201907L
to decide if the attribute is supported or not.

This commit also introduces a syntax-only test, and also applies
the new macro to QMutexLocker, because not all platforms in the
CI build and run unit tests.

Fixes: QTBUG-104161
Change-Id: Ib4230661a5ad5e8af0d67b21b034486ebcd67562
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-04-30 19:42:29 +02:00
..
q20 Short live q20::to_address! 2023-03-31 13:10:12 +01:00
q_func_info tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qcompare tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qflags QTypeInfo: remove further usages of isPointer / isIntegral 2022-12-30 01:51:27 +01:00
qfloat16 tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qgetputenv tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qglobal Short live Q_NODISCARD_CTOR 2023-04-30 19:42:29 +02:00
qglobalstatic tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qhooks tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qkeycombination tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qlogging tst_qmessagehandler: fix QtTest warnings about duplicate row names 2023-02-23 10:33:39 -08:00
qnativeinterface Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00
qnumeric tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qoperatingsystemversion tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qrandomgenerator tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qtendian tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
qxp Change the license of all CMakeLists.txt and *.cmake files to BSD 2022-08-23 23:58:42 +02:00
CMakeLists.txt Short live q20::to_address! 2023-03-31 13:10:12 +01:00