qt5base-lts/tests/auto
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
..
bic/data Add binary compatibility file built against 6.5.0 2023-04-19 15:40:36 +00:00
cmake Introduce the qt_internal_project_setup macro 2023-04-24 14:20:25 +02:00
concurrent tst_qtconcurrentrun: fix UB (uninit'ed values) 2023-03-31 11:32:46 +02:00
corelib Short live Q_NODISCARD_CTOR 2023-04-30 19:42:29 +02:00
dbus QThread: add sleep(std::chrono::nanoseconds) overload 2023-03-13 23:26:28 +02:00
gui rhi: Add another resource update batch autotest 2023-04-27 16:21:36 +02:00
guiapplauncher Move Weather Anchor Layout example to manual tests 2023-03-02 05:55:57 +01:00
network tst_QSslCertificate: Make it easier to check which backend is used 2023-04-25 23:39:24 +02:00
opengl tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
other Network tests: drop testing ftp proxy server 2023-04-20 16:10:03 +02:00
printsupport tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
shared tests: remove PlatformInputContext::filterEvent() 2023-01-18 13:21:06 +01:00
sql QSqlField: add move ctor & move operator 2023-04-26 19:56:07 +00:00
testlib Rid of 'special case' markers 2023-04-13 18:30:58 +02:00
tools Fix another warning when comparing size_t and qsizetype 2023-04-18 00:10:56 +02:00
wasm Support filter list for file input when opening a file on WASM 2023-03-07 12:50:41 +01:00
widgets QTabBar: don't scroll when laying out the tabs 2023-04-26 12:50:49 +02:00
xml QDomDocument: no longer drop a provided 'standalone' attribute if 'no' 2023-04-24 21:49:29 +02:00
CMakeLists.txt tests: Remove remains of qmake conversion from CMakeLists.txt files 2023-02-17 21:56:49 +01:00
network-settings.h Use SPDX license identifiers 2022-05-16 16:37:38 +02:00