aboutsummaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2023-04-03 13:22:36 -0700
committerCraig Topper <craig.topper@sifive.com>2023-04-03 13:22:36 -0700
commit475dd6f626ee2679578ed570e9fb78f7e957a36d (patch)
tree20629a79b547640708ae86300a30a92bcf0f39dc /llvm
parent8c3ae74ab147cad84f6bebc6d30a6e5a309f0d9f (diff)
downloadllvm-475dd6f626ee2679578ed570e9fb78f7e957a36d.zip
llvm-475dd6f626ee2679578ed570e9fb78f7e957a36d.tar.gz
llvm-475dd6f626ee2679578ed570e9fb78f7e957a36d.tar.bz2
[SmallVector] Add an explicit SmallVector(size_t Size) constructor.
Previously we used the SmallVector(size_t Size, const T& Value) constructor with a default constructed Value. That will copy construct every element in the vector, but not all types can be copy constructed. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D147426
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/ADT/SmallVector.h7
-rw-r--r--llvm/unittests/ADT/SmallVectorTest.cpp5
2 files changed, 11 insertions, 1 deletions
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 98dce89..93d9491 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -1206,7 +1206,12 @@ public:
this->destroy_range(this->begin(), this->end());
}
- explicit SmallVector(size_t Size, const T &Value = T())
+ explicit SmallVector(size_t Size)
+ : SmallVectorImpl<T>(N) {
+ this->resize(Size);
+ }
+
+ SmallVector(size_t Size, const T &Value)
: SmallVectorImpl<T>(N) {
this->assign(Size, Value);
}
diff --git a/llvm/unittests/ADT/SmallVectorTest.cpp b/llvm/unittests/ADT/SmallVectorTest.cpp
index fd3780a..8465257 100644
--- a/llvm/unittests/ADT/SmallVectorTest.cpp
+++ b/llvm/unittests/ADT/SmallVectorTest.cpp
@@ -171,6 +171,11 @@ LLVM_ATTRIBUTE_USED void CompileTest() {
V.resize(42);
}
+TEST(SmallVectorTest, ConstructNonCopyableTest) {
+ SmallVector<NonCopyable, 0> V(42);
+ EXPECT_EQ(V.size(), 42);
+}
+
// Assert that v contains the specified values, in order.
template <typename VectorT>
void assertValuesInOrder(VectorT &v, size_t size, ...) {