[llvm] [ADT] Use static_assert in PackedVector (PR #164142)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 18 19:40:03 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/164142.diff
1 Files Affected:
- (modified) llvm/include/llvm/ADT/PackedVector.h (+2-3)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/164142
More information about the llvm-commits
mailing list