summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2020-07-30 11:50:01 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2020-08-18 12:55:38 +0200
commit0bd647fa4ffb3319bf3b1d044441b137910629e1 (patch)
treed9c16557930ff31da1fe91ae2a98eec2ede52086 /src/corelib/tools
parent56f1208f9e6b9a0fa7a121ed46883e62eaf57088 (diff)
Reorder operations to align with exception model in qarraydataops.h
Fixed order of certain operations to better handle situations when exceptions occur Change-Id: Ia2075c37b4b7653067dfa6a82252cbb12b96708f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qarraydataops.h27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h
index 369a8ae574..57440703e5 100644
--- a/src/corelib/tools/qarraydataops.h
+++ b/src/corelib/tools/qarraydataops.h
@@ -495,13 +495,17 @@ struct QGenericArrayOps
// Construct new elements in array
while (writeIter != step1End) {
- --readIter, --writeIter;
- new (writeIter) T(*readIter);
+ --readIter;
+ // If exception happens on construction, we should not call ~T()
+ new (writeIter - 1) T(*readIter);
+ --writeIter;
}
while (writeIter != end) {
- --e, --writeIter;
- new (writeIter) T(*e);
+ --e;
+ // If exception happens on construction, we should not call ~T()
+ new (writeIter - 1) T(*e);
+ --writeIter;
}
destroyer.commit();
@@ -538,13 +542,17 @@ struct QGenericArrayOps
// Construct new elements in array
while (writeIter != step1End) {
- --readIter, --writeIter;
- new (writeIter) T(*readIter);
+ --readIter;
+ // If exception happens on construction, we should not call ~T()
+ new (writeIter - 1) T(*readIter);
+ --writeIter;
}
while (writeIter != end) {
- --n, --writeIter;
- new (writeIter) T(t);
+ --n;
+ // If exception happens on construction, we should not call ~T()
+ new (writeIter - 1) T(t);
+ --writeIter;
}
destroyer.commit();
@@ -597,8 +605,9 @@ struct QGenericArrayOps
// destroy the final elements at the end
// here, b points to the new end and e to the actual end
do {
- (--e)->~T();
+ // Exceptions or not, dtor called once per instance
--this->size;
+ (--e)->~T();
} while (e != b);
}