From fe7ecaf39135fabe60e823ac127a9a5782b3e686 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 16 Oct 2025 11:01:13 -0700 Subject: [PATCH] [ADT] Use static_assert in PackedVector This patch replaces an intentionally undefined template specialization: template class PackedVector; with: static_assert(BitNum > 0, "BitNum must be > 0"); This way, the compiler diagnostic on a use of PackedVector improves from: error: implicit instantiation of undefined template 'llvm::PackedVector' to: error: static assertion failed due to requirement '0U > 0': BitNum must be > 0 --- llvm/include/llvm/ADT/PackedVector.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/ADT/PackedVector.h b/llvm/include/llvm/ADT/PackedVector.h index 09c20e39d1552..57e41979b4ce2 100644 --- a/llvm/include/llvm/ADT/PackedVector.h +++ b/llvm/include/llvm/ADT/PackedVector.h @@ -29,6 +29,8 @@ namespace llvm { /// an assertion. template class PackedVector { + static_assert(BitNum > 0, "BitNum must be > 0"); + BitVectorTy Bits; // Keep track of the number of elements on our own. // We always maintain Bits.size() == NumElements * BitNum. @@ -133,9 +135,6 @@ class PackedVector { BitVectorTy &raw_bits() { return Bits; } }; -// Leave BitNum=0 undefined. -template class PackedVector; - } // end namespace llvm #endif // LLVM_ADT_PACKEDVECTOR_H