diff --git a/compiler-rt/lib/scudo/standalone/string_utils.h b/compiler-rt/lib/scudo/standalone/string_utils.h index 6e00b637797374..cf61e150f20e52 100644 --- a/compiler-rt/lib/scudo/standalone/string_utils.h +++ b/compiler-rt/lib/scudo/standalone/string_utils.h @@ -40,7 +40,7 @@ class ScopedString { void appendString(int Width, int MaxChars, const char *S); void appendPointer(u64 ptr_value); - Vector String; + Vector String; }; void Printf(const char *Format, ...) FORMAT(1, 2); diff --git a/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp b/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp index 1547824c117639..a972d24a626889 100644 --- a/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp @@ -11,7 +11,7 @@ #include "vector.h" TEST(ScudoVectorTest, Basic) { - scudo::Vector V; + scudo::Vector V; EXPECT_EQ(V.size(), 0U); V.push_back(42); EXPECT_EQ(V.size(), 1U); @@ -23,7 +23,7 @@ TEST(ScudoVectorTest, Basic) { } TEST(ScudoVectorTest, Stride) { - scudo::Vector V; + scudo::Vector V; for (scudo::uptr I = 0; I < 1000; I++) { V.push_back(I); EXPECT_EQ(V.size(), I + 1U); @@ -34,7 +34,7 @@ TEST(ScudoVectorTest, Stride) { } TEST(ScudoVectorTest, ResizeReduction) { - scudo::Vector V; + scudo::Vector V; V.push_back(0); V.push_back(0); EXPECT_EQ(V.size(), 2U); @@ -48,7 +48,7 @@ TEST(ScudoVectorTest, ResizeReduction) { // Verify that if the reallocate fails, nothing new is added. TEST(ScudoVectorTest, ReallocateFails) { - scudo::Vector V; + scudo::Vector V; scudo::uptr capacity = V.capacity(); // Get the current address space size. diff --git a/compiler-rt/lib/scudo/standalone/vector.h b/compiler-rt/lib/scudo/standalone/vector.h index ca10cc281d7701..98b3db4ad6980a 100644 --- a/compiler-rt/lib/scudo/standalone/vector.h +++ b/compiler-rt/lib/scudo/standalone/vector.h @@ -21,7 +21,7 @@ namespace scudo { // implementation supports only POD types. // // NOTE: This class is not meant to be used directly, use Vector instead. -template class VectorNoCtor { +template class VectorNoCtor { public: T &operator[](uptr I) { DCHECK_LT(I, Size); @@ -116,18 +116,21 @@ template class VectorNoCtor { uptr CapacityBytes = 0; uptr Size = 0; - T LocalData[256 / sizeof(T)] = {}; + T LocalData[StaticNumEntries] = {}; MemMapT ExternalBuffer; }; -template class Vector : public VectorNoCtor { +template +class Vector : public VectorNoCtor { public: - constexpr Vector() { VectorNoCtor::init(); } + static_assert(StaticNumEntries > 0U, + "Vector must have a non-zero number of static entries."); + constexpr Vector() { VectorNoCtor::init(); } explicit Vector(uptr Count) { - VectorNoCtor::init(Count); + VectorNoCtor::init(Count); this->resize(Count); } - ~Vector() { VectorNoCtor::destroy(); } + ~Vector() { VectorNoCtor::destroy(); } // Disallow copies and moves. Vector(const Vector &) = delete; Vector &operator=(const Vector &) = delete;