[llvm] 5805e4d - [ADT] Use static_assert in PackedVector (#164142)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 19 08:33:56 PDT 2025


Author: Kazu Hirata
Date: 2025-10-19T08:33:52-07:00
New Revision: 5805e4d1a05e5faf805bb28b5ba5604d58834e45

URL: https://github.com/llvm/llvm-project/commit/5805e4d1a05e5faf805bb28b5ba5604d58834e45
DIFF: https://github.com/llvm/llvm-project/commit/5805e4d1a05e5faf805bb28b5ba5604d58834e45.diff

LOG: [ADT] Use static_assert in PackedVector (#164142)

This patch replaces an intentionally undefined template
specialization:

  template <typename T> class PackedVector<T, 0>;

with:

  static_assert(BitNum > 0, "BitNum must be > 0");

This way, the compiler diagnostic on a use of PackedVector<T, 0>
improves from:

  error: implicit instantiation of undefined template
  'llvm::PackedVector<unsigned int, 0>'

to:

  error: static assertion failed due to requirement '0U > 0': BitNum
  must be > 0

Added: 
    

Modified: 
    llvm/include/llvm/ADT/PackedVector.h

Removed: 
    


################################################################################
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 <typename T, unsigned BitNum, typename BitVectorTy = BitVector>
 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 <typename T> class PackedVector<T, 0>;
-
 } // end namespace llvm
 
 #endif // LLVM_ADT_PACKEDVECTOR_H


        


More information about the llvm-commits mailing list