[PATCH] D126401: [ADT] Explicitly delete copy/move constructors and operator= in IntervalMap
Krzysztof Parzyszek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 26 07:58:42 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaee6b8efd09c: [ADT] Explicitly delete copy/move constructors and operator= in IntervalMap (authored by kparzysz).
Changed prior to commit:
https://reviews.llvm.org/D126401?vs=432056&id=432288#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126401/new/
https://reviews.llvm.org/D126401
Files:
llvm/include/llvm/ADT/IntervalMap.h
llvm/unittests/ADT/IntervalMapTest.cpp
Index: llvm/unittests/ADT/IntervalMapTest.cpp
===================================================================
--- llvm/unittests/ADT/IntervalMapTest.cpp
+++ llvm/unittests/ADT/IntervalMapTest.cpp
@@ -8,6 +8,7 @@
#include "llvm/ADT/IntervalMap.h"
#include "gtest/gtest.h"
+#include <type_traits>
using namespace llvm;
@@ -17,6 +18,15 @@
typedef IntervalMap<unsigned, unsigned, 4,
IntervalMapHalfOpenInfo<unsigned>> UUHalfOpenMap;
+static_assert(!std::is_copy_constructible<UUMap>::value,
+ "IntervalMap copy constructor should be deleted");
+static_assert(!std::is_move_constructible<UUMap>::value,
+ "IntervalMap move constructor should be deleted");
+static_assert(!std::is_copy_assignable<UUMap>::value,
+ "IntervalMap copy assignment should be deleted");
+static_assert(!std::is_move_assignable<UUMap>::value,
+ "IntervalMap move assignment should be deleted");
+
// Empty map tests
TEST(IntervalMapTest, EmptyMap) {
UUMap::Allocator allocator;
Index: llvm/include/llvm/ADT/IntervalMap.h
===================================================================
--- llvm/include/llvm/ADT/IntervalMap.h
+++ llvm/include/llvm/ADT/IntervalMap.h
@@ -1042,6 +1042,17 @@
new(&rootLeaf()) RootLeaf();
}
+ // The default copy/move constructors and assignment operators would perform
+ // a shallow copy, leading to an incorrect internal state. To prevent
+ // accidental use, explicitly delete these operators.
+ // If necessary, implement them to perform a deep copy.
+ IntervalMap(const IntervalMap &Other) = delete;
+ IntervalMap(IntervalMap &&Other) = delete;
+ // Note: these are already implicitly deleted, because RootLeaf (union
+ // member) has a non-trivial assignment operator (because of std::pair).
+ IntervalMap &operator=(const IntervalMap &Other) = delete;
+ IntervalMap &operator=(IntervalMap &&Other) = delete;
+
~IntervalMap() {
clear();
rootLeaf().~RootLeaf();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126401.432288.patch
Type: text/x-patch
Size: 1997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220526/3e580a0a/attachment.bin>
More information about the llvm-commits
mailing list