[PATCH] D119580: [LLVM][Support] Delete non-const lvalue ref "copy" constructor of BumpPtrAllocatorImpl
Zixu Wang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 11 15:05:47 PST 2022
zixuw updated this revision to Diff 408073.
zixuw added a comment.
Fix template parameters.
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 AT, size_t SS, size_t ST, size_t GD>
+ BumpPtrAllocatorImpl(BumpPtrAllocatorImpl<AT, SS, ST, GD> &) = 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.408073.patch
Type: text/x-patch
Size: 1621 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220211/dda98904/attachment.bin>
More information about the llvm-commits
mailing list