QDuplicateTracker: don't value-initialize the stack buffer

The typical usage of a QDuplicateTracker should be to pass the
guesstimate for the number of entries as a constructor argument, or,
failing that, default-construct the object. In those cases, everything
is peachy:

   QDuplicateTracker<int> seen(n);
   QDuplicateTracker<int> seen;

But for users that subscribe to a AAA view and use

   auto seen = QDuplicateTracker<int>{};

or that emplace() a QDuplicateTracker in e.g. std::optional, we need
to make sure that value-initializing QDuplicateTracker doesn't
value-initialize the internal buffer (which can be several KiB in
size).

So don't = default the default ctor, but implement it as empty.

Amends f21a6d409ea0504c64cd72861fc16b6f3e080086.

Pick-to: 6.8 6.5 6.2 5.15
Change-Id: I930f40d2bb85b74d2216378d8b8ca854a53a49e4
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 15154fa4c5d216b1c943a3b37be24f5fb2e4fa73)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-01-23 19:07:51 +01:00 committed by Qt Cherry-pick Bot
parent 9df9412335
commit 6ba8e9875a

View File

@ -76,7 +76,7 @@ public:
false
#endif
;
QDuplicateTracker() = default;
QDuplicateTracker() {} // don't `= default`, lest we value-initialize `buffer`
explicit QDuplicateTracker(qsizetype n)
#ifdef __cpp_lib_memory_resource
: set{size_t(n), &res}