summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qscopeguard.h
Commit message (Collapse)AuthorAgeFilesLines
* Remove all class-level [[nodiscard]] from the code-baseMarc Mutz2023-06-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A class-level [[nodiscard]] used to be the only way to get a waring for code such as QMutexLocker(&mutex); with original C++17 means. This was because a few of our compilers would warn about the presence of [[nodiscard]] on ctors, which is really the semantics we want: we don't want to prevent users from passing QMutexLocker out of functions and users of those functions from ignoring the return value, if they so choose. That should be the choice of the author of the function returning such types, not ours. So QUIP-0019 makes class-level [[nodiscard]] conditional on proper rationale in the user docs (or the commit message in case of private API). Since none of the existing uses really strikes this author as particularly convincing, remove them all. All these classes have gotten Q_NODISCARD_CTOR on all their ctors, so we continue to provide the same true positive warnings, minus the false positives when returning from functions, at least on the majority of compilers (and it's not as if all compilers interpreted a class-level [[nodiscard]] as a trigger to warn on the initial example of this commit message). Task-number: QTBUG-104164 Pick-to: 6.6 Change-Id: I163356486e7c80f9d69bf67023010a88233fe662 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Mark all ctors of [[nodiscard]] classes as Q_NODISCARD_CTORMarc Mutz2023-06-201-0/+3
| | | | | | | | | | | | | | | | This works around around the difference in class-level [[nodiscard]] behavior between Clang and GCC. While Clang already warns about QClass(~~~args~~~); when QClass is marked as [[nodiscard]] at the class level, GCC does not, and requires the ctor to be marked as [[nodiscard]] instead. Pick-to: 6.6 Fixes: QTBUG-104164 Change-Id: Ifd7076ee422fb9472ae8bbba43d9bfeee1968a78 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Replace qExchange calls with std::exchangeFabian Kosmale2022-09-281-1/+1
| | | | | | | | | | | | | | | | | | | | | qExchange is one of the few remaining functionalities that have not been moved out of qglobal. Given that std::exchange exists in the standard, we can simply move to it everywhere... ...if it weren't for the fact that std::exchange is only constexpr in C++20, and only has its noexceptness specified in (most likely) C++23. Still, we want to move to the existing std functionality where possible, to allow the removal of qglobal includes in lieu of something more fine-grained in the future. So leave any constexpr calls[1] alone for now (and observe that none of our current usages cares about the conditional noexceptness), but replace everything else. [1] QScopedValueRollback' ctor and QExplicitlySharedDataPointerV2::take Task-number: QTBUG-99313 Change-Id: I599cb9846cf319c7ffd3457130938347a75aad25 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use SPDX license identifiersLucie Gérard2022-05-161-39/+3
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Remove checks for features available in C++17Ievgenii Meshcheriakov2021-10-021-2/+0
| | | | | | | | | | This patch removes most of the checks that are made using C++20 __cpp_* macros for features available in C++17 and earlier. Library feature check macros (__cpp_lib_*) are unaffected. Change-Id: I557b2bd0d4ff09b13837555e9880eb28e0355f64 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace Q_REQUIRED_RESULT with [[nodiscard]]Allan Sandfeld Jensen2020-09-251-11/+2
| | | | | | | It was already used many places directly making the code inconsistent. Change-Id: I3b14bc6c333640fb3ba33c71eba97e78c973e44b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Doc: Fix \fn command for qScopeGuard(F &&f)Topi Reinio2020-03-261-0/+1
| | | | | | | | and tag it in the header file to ensure the documentation is matched. Change-Id: Id1e7cd395ca0ec337845da9a207bfbf95db01064 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QScopeGuard: Fix build failures with qScopeGuard()Kari Oikarinen2020-02-011-11/+4
| | | | | | | | | | | | | | | Partially reverts 4f077b7e5ff1081afc0e362bdab6522c2b7ee43b. Can't overload with forwarding references and lvalue references. Use a single forwarding reference overload, but take care of not trying to create a QScopeGuard of reference type and forward instead of moving. Add tests to ensure calling with both lvalues and rvalues is possible. Change-Id: Ia034afe0a8feb08246c2c7c154a85cae37421c98 Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* QScopeGuard: Make constructor publicKari Oikarinen2020-01-301-12/+25
| | | | | | | | | | | | With Class Template Argument Deduction users might want to use the constructor itself instead of a separate helper function. In both cases it's possible to let the compiler deduce the template arguments. Try to make the usefulness of the helper function in the absence of CTAD still clear in the documentation. Change-Id: I9b07983c1fb276a6dd9e7ed4c3e606764e9b68ca Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* Don't wrap feature detection macros with QT_HAS_FOO() variantsTor Arne Vestbø2019-12-101-2/+2
| | | | | | | | | | | | | | | | | Using wrappers for these macros is problematic when for example passing the -frewrite-includes flag to preprocess sources before shipping off to distcc or Icecream. It will also start producing warnings when compilers implement http://eel.is/c++draft/cpp.cond#7.sentence-2. See for example https://reviews.llvm.org/D49091 Both https://clang.llvm.org/docs/LanguageExtensions.html and the SD-6 document at https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations recommend defining '__has_foo(x) 0' as a fallback for compilers without the macros, so that's what we go for. Change-Id: I0298cd3b4a6ff6618821e34642a5ddd6728be767 Reviewed-by: Alex Richardson <arichardson.kde@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix compilation error on compilers not supporting [[nodiscard]]Jędrzej Nowacki2019-05-211-4/+4
| | | | | | | | | | | | | | | | | | __warn_unused_result__ and [[nodiscard]] both are masked by Q_REQUIRED_RESULT but there are some minor differences between them. In general [[nodiscard]] is more flexible while __warn_unused_result__ can cause warnings in some contexts, for example: error #2621: attribute "__warn_unused_result__" does not apply here error #3058: GNU attributes on a template redeclaration have no effect That is a fix for regression caused by b91e6f6f40864d54903d707d7f19a9732188b670. Change-Id: Icf11b832f31e714a88536828051f4b7f348cdb36 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* QScopeGuard: some cleanupsMarc Mutz2019-05-211-3/+2
| | | | | | | | | | | | | | Use qExchange() in the move ctor and pass the function object by rvalue ref. This saves one move construction and doesn't produce unexpected results. The qScopeGuard free function should take the function object by value, because it decays and because we can't create an rvalure reference in a deduced context. But once we're inside qScopeGuard, the extra object isn't needed anymore, so optimize it away. Change-Id: I94cbc45f9bf6ca086e100efd922a0b4643a81671 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Replace Q_DECL_NOEXCEPT with noexcept in corelibAllan Sandfeld Jensen2019-04-031-3/+3
| | | | | | | In preparation of Qt6 move away from pre-C++11 macros. Change-Id: I44126693c20c18eca5620caab4f7e746218e0ce3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Issue a warning about unused result of qScopeGuard and QScopeGuardJędrzej Nowacki2019-04-021-1/+10
| | | | | | | | | If the result is unassigned then resulting QScopeGuard is destroyed immediately, we can warn about it, as it is definitely a bug. Change-Id: I627b05cecb3d0e62dbc24373e621f2be36d9b324 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Introduce QScopeGuardSérgio Martins2018-07-211-0/+96
A RAII style class which calls a function at end of scope. Example usage: auto cleanup = qScopeGuard([] { <my cleanup code> ; }); [ChangeLog][QtCore] Introduced QScopeGuard. Task-number: QTBUG-62894 Change-Id: Ife67f5c76255a1fafbae03367263da0bac9a0070 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>