summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qassert.h
Commit message (Collapse)AuthorAgeFilesLines
* Long live Q_UNREACHABLE_RETURN()!Marc Mutz2022-10-151-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a combination of Q_UNREACHABLE() with a return statement. ATM, the return statement is unconditionally included. If we notice that some compilers warn about return after __builtin_unreachable(), then we can map Q_UNREACHABLE_RETURN(...) to Q_UNREACHABLE() without having to touch all the code that uses explicit Q_UNREACHABLE() + return. The fact that Boost has BOOST_UNREACHABLE_RETURN() indicates that there are compilers that complain about a lack of return after Q_UNREACHABLE (we know that MSVC, ICC, and GHS are among them), as well as compilers that complained about a return being present (Coverity). Take this opportunity to properly adapt to Coverity, by leaving out the return statement on this compiler. Apply the macro around the code base, using a clang-tidy transformer rule: const std::string unr = "unr", val = "val", ret = "ret"; auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(", ifBound(val, cat(node(val)), cat("")), ")"); auto ignoringSwitchCases = [](auto stmt) { return anyOf(stmt, switchCase(subStmt(stmt))); }; makeRule( stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)), nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))), {changeTo(node(unr), cat(makeUnreachableReturn, ";")), // TODO: why is the ; lost w/o this? changeTo(node(ret), cat(""))}, cat("use ", makeUnreachableReturn)) ); where nextStmt() is copied from some upstream clang-tidy check's private implementation and subStmt() is a private matcher that gives access to SwitchCase's SubStmt. A.k.a. qt-use-unreachable-return. There were some false positives, suppressed them with NOLINTNEXTLINE. They're not really false positiives, it's just that Clang sees the world in one way and if conditonal compilation (#if) differs for other compilers, Clang doesn't know better. This is an artifact of matching two consecutive statements. I haven't figured out how to remove the empty line left by the deletion of the return statement, if it, indeed, was on a separate line, so post-processed the patch to remove all the lines matching ^\+ *$ from the diff: git commit -am meep git reset --hard HEAD^ git diff HEAD..HEAD@{1} | sed '/^\+ *$/d' | recountdiff - | patch -p1 [ChangeLog][QtCore][QtAssert] Added Q_UNREACHABLE_RETURN() macro. Change-Id: I9782939f16091c964f25b7826e1c0dbd13a71305 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qassert.h: Include qtcoreexports.hFabian Kosmale2022-09-271-0/+1
| | | | | | | Else we cannot use Q_CORE_EXPORT Change-Id: I2ccb6a6a9abeaad1de8d541224e055f524d6d07b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove qtnamespacemacros.h and use qtconfigmacros.h insteadSona Kurazyan2022-08-191-1/+1
| | | | | | | Change-Id: Ibae6e6e255c1bb1ee52839a051d585de81833bf9 Pick-to: 6.4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Move Q_STATIC_ASSERT* macros to qassert.hSona Kurazyan2022-08-111-0/+25
| | | | | | | | | | | | | | This requires moving the include statement for qassert.h in qglobal.h up, outside the #if defined(__cplusplus) check, to make the macros available when __cplusplus isn't defined. Also move qt_noop() up, before the include of qassert.h, this will later go to a separate header. Task-number: QTBUG-99313 Change-Id: I0f3f1ca77819a86623eebaf8adeba226c190fd37 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move Q_ASSUME and Q_UNREACHABLE to qassert.hSona Kurazyan2022-08-051-0/+13
| | | | | | | | | As a drive-by, add a link back to Q_ASSUME() in Q_LIKELY() docs. Change-Id: I4a46e281d0fbf55c11001f15667fcc4faa3b0c5b Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Move Q_CHECK_PTR and related helpers to qassert.hSona Kurazyan2022-08-051-0/+17
| | | | | | | Task-number: QTBUG-99313 Change-Id: Ia4152f0aad15975d8aebbbc506c8a76c8fbe144f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Extract header qassert.h from qglobal.hSona Kurazyan2022-08-051-0/+48
For now qassert.h is included in the middle of qglobal.h, since some of the code below needs it, but this will be cleaned up when that code is moved in its own header. Task-number: QTBUG-99313 Change-Id: I2cdfed44f5c8772c1dad4797cf8edc6cb4c964b4 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>