summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qassert.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Move qAbort from qglobal.cpp to qassert.cppThiago Macieira2024-03-061-0/+67
| | | | | | | | | | | It makes more sense there, as all the other functions in that file are about early termination. This allows us to remove qglobal.cpp from the bootstrap library, because qglobal.cpp now only has the callback tables. Amends 8f13af5d7b9b659208a8a93e6581d30b434dae1f. Change-Id: I01ec3c774d9943adb903fffd17b7ea92404bdbd3 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Deprecate Q_ASSUMEThiago Macieira2023-05-041-19/+10
| | | | | | | | | | | | No replacement provided because we didn't agree on how to do it. But the current implementation is bad (with GCC, at least), so tell people to stop using it. [ChangeLog][Deprecations] The Q_ASSUME macro is now deprecated. Do not use it in new code and consider removing it from existing code. Change-Id: Idd5e1bb52be047d7b4fffffd175322ee3402756b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Long live Q_UNREACHABLE_RETURN()!Marc Mutz2022-10-151-1/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fix the license headersSona Kurazyan2022-09-211-1/+1
| | | | | | | These were copied from *.qdoc files by a mistake. Change-Id: I2379422c2c8558bd8c2111170d0c1d97f06797da Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Move Q_ASSUME and Q_UNREACHABLE to qassert.hSona Kurazyan2022-08-051-0/+61
| | | | | | | | | 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/+66
| | | | | | | 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/+74
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>