[PATCH] D119580: [LLVM][Support] Delete "copy" constructor of BumpPtrAllocatorImpl
Zixu Wang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 11 14:28:08 PST 2022
zixuw updated this revision to Diff 408057.
zixuw added a comment.
Add unit test case with `std::is_[copy]_constructible`
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119580/new/
https://reviews.llvm.org/D119580
Files:
llvm/include/llvm/Support/Allocator.h
llvm/unittests/Support/AllocatorTest.cpp
Index: llvm/unittests/Support/AllocatorTest.cpp
===================================================================
--- llvm/unittests/Support/AllocatorTest.cpp
+++ llvm/unittests/Support/AllocatorTest.cpp
@@ -9,6 +9,7 @@
#include "llvm/Support/Allocator.h"
#include "gtest/gtest.h"
#include <cstdlib>
+#include <type_traits>
using namespace llvm;
@@ -45,6 +46,16 @@
EXPECT_EQ(1U, Alloc.GetNumSlabs());
}
+TEST(AllocatorTest, NoCopy) {
+ constexpr bool CopyConstructible =
+ std::is_copy_constructible<BumpPtrAllocator>::value;
+ EXPECT_FALSE(CopyConstructible);
+
+ constexpr bool NonConstLRefConstructible =
+ std::is_constructible<BumpPtrAllocator, BumpPtrAllocator &>::value;
+ EXPECT_FALSE(NonConstLRefConstructible);
+}
+
// Allocate enough bytes to create three slabs.
TEST(AllocatorTest, ThreeSlabs) {
BumpPtrAllocator Alloc;
Index: llvm/include/llvm/Support/Allocator.h
===================================================================
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -79,6 +79,11 @@
BumpPtrAllocatorImpl(T &&Allocator)
: AllocatorT(std::forward<T &&>(Allocator)) {}
+ // BumpPtrAllocator shouldn't be copyable. Explicitly delete this
+ // specialization of the perfect-forwarding constructor above.
+ template <typename T>
+ BumpPtrAllocatorImpl(BumpPtrAllocatorImpl<T> &) = delete;
+
// Manually implement a move constructor as we must clear the old allocator's
// slabs as a matter of correctness.
BumpPtrAllocatorImpl(BumpPtrAllocatorImpl &&Old)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119580.408057.patch
Type: text/x-patch
Size: 1574 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220211/8e04ef81/attachment-0001.bin>
More information about the llvm-commits
mailing list