217f2ab3eb
Instead of duplicating the logic of resize() to avoid three stores to (ptr, a, s), and getting the memory management wrong (malloc()ed ptr leaked when a following default-construction failed), simply call the QVLA default ctor followed by std::uninitialized_default_construct_n(). After we called the QVLA default ctor, the lifetime of this object has begun, so if the following code throws, ~QVLA will be called to clean up. This was not the case when we didn't delegate the ctor: if the body of this ctor threw, ~QVLA would _not_ have been called, since the lifetime of the object had never started. Since the dtor may now run, we need to maintain the class invariants, so we can't just set the size() before we have constructed all elements. This is where std::uninitialized_default_construct_n() comes in: it's strongly exception-safe, so if a constructor throws, it will destroy all previously-constructed elements, so that either we fail and size() == 0 is true or it doesn't, then we can set size() to asize. Pick-to: 6.5 6.4 6.4.3 6.2 Change-Id: I03408d8a473e8a31fa0086ef5ac551ce46a758f8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> |
||
---|---|---|
.github/workflows | ||
bin | ||
cmake | ||
coin | ||
config.tests | ||
dist | ||
doc | ||
examples | ||
lib | ||
libexec | ||
LICENSES | ||
mkspecs | ||
qmake | ||
src | ||
tests | ||
util | ||
.cmake.conf | ||
.gitattributes | ||
.gitignore | ||
.lgtm.yml | ||
.tag | ||
CMakeLists.txt | ||
conanfile.py | ||
config_help.txt | ||
configure | ||
configure.bat | ||
configure.cmake | ||
dependencies.yaml | ||
qt_cmdline.cmake | ||
sync.profile |