diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-10-02 18:27:51 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-10-05 20:19:40 +0200 |
commit | 1219dbcd123a8001785a1e58452d9abfdfc43471 (patch) | |
tree | 552d991302c6f2f8f3ced486495de277098609b7 /src/corelib/kernel/qpointer.h | |
parent | c0ba4ad49d9099e723518d9f4384e00bfb6ae1a7 (diff) |
QPointer: ensure construction from nullptr is constinit'able
Construction from nullptr wasn't, before, because it was using the
QPointer(T*) constructor, which cannot be constexpr. Add a constexpr
QPointer(std::nullptr_t) constructor to enable this use-case.
This requires to mark the (T*) constructor as Q_WEAK_OVERLOAD,
otherwise legacy construction from a literal 0 would be ambiguous.
No documentation changes needed, as the set of valid expressions
(apart from constinit'ing) has not changed. Mention the nullptr ctor,
though, without \since.
Add a test to confirm that contruction from derived still works.
Change-Id: If9d5281f6eca0c408a69f03fecba64a70a0c9cf0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qpointer.h')
-rw-r--r-- | src/corelib/kernel/qpointer.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/corelib/kernel/qpointer.h b/src/corelib/kernel/qpointer.h index 8d63f2bc0e..39e4ba3e0f 100644 --- a/src/corelib/kernel/qpointer.h +++ b/src/corelib/kernel/qpointer.h @@ -30,6 +30,9 @@ public: Q_NODISCARD_CTOR QPointer() noexcept = default; Q_NODISCARD_CTOR + constexpr QPointer(std::nullptr_t) noexcept : QPointer{} {} + Q_WEAK_OVERLOAD + Q_NODISCARD_CTOR inline QPointer(T *p) : wp(p, true) { } // compiler-generated copy/move ctor/assignment operators are fine! // compiler-generated dtor is fine! |