summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qvarlengtharray.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-11-09 17:27:04 +0100
committerLars Knoll <lars.knoll@qt.io>2020-11-17 11:46:28 +0100
commit621c05e3b1869a524c1617fe9d1d178af3f7f227 (patch)
tree0fbfa0470e670a4550db2c6ea8c2a26885dbd6a9 /src/corelib/tools/qvarlengtharray.h
parent872f18bbd66d32862b9c10805ee125c466671df4 (diff)
Don't allow storing types that throw in the destructor in our containers
Types that throw in their destructors are strongly discouraged in C++, and even the STL doesn't define what happens if such types are stored in their containers. Make this more explicit for Qt and disallow storing those types in our containers. This will hopefully preempty any potential future bug reports about us not handling such a case. It also helps simplify some code in QList and other cases and makes it possible to explicitly mark more methods as noexcept. Some care needs to be taken where to add the static asserts, so that we don't disallow forward declarations of types stored in containers. Place the static assert into the destructor of the container where possible or otherwise into the templated d-pointer. Change-Id: If3aa40888f668d0f1b6c6b3ad4862b169d31280e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/tools/qvarlengtharray.h')
-rw-r--r--src/corelib/tools/qvarlengtharray.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index b538cf292d..975d088a48 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -60,6 +60,8 @@ QT_BEGIN_NAMESPACE
template<class T, qsizetype Prealloc>
class QVarLengthArray
{
+ static_assert(std::is_nothrow_destructible_v<T>, "Types with throwing destructors are not supported in Qt containers.");
+
public:
QVarLengthArray() : QVarLengthArray(0) {}