Skip to content

Commit 5805e4d

Browse files
[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
1 parent a0a840a commit 5805e4d

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

llvm/include/llvm/ADT/PackedVector.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ namespace llvm {
2929
/// an assertion.
3030
template <typename T, unsigned BitNum, typename BitVectorTy = BitVector>
3131
class PackedVector {
32+
static_assert(BitNum > 0, "BitNum must be > 0");
33+
3234
BitVectorTy Bits;
3335
// Keep track of the number of elements on our own.
3436
// We always maintain Bits.size() == NumElements * BitNum.
@@ -133,9 +135,6 @@ class PackedVector {
133135
BitVectorTy &raw_bits() { return Bits; }
134136
};
135137

136-
// Leave BitNum=0 undefined.
137-
template <typename T> class PackedVector<T, 0>;
138-
139138
} // end namespace llvm
140139

141140
#endif // LLVM_ADT_PACKEDVECTOR_H

0 commit comments

Comments
 (0)