llvm.org GIT mirror llvm / 167cdd0
[ADT] Defend against getting slightly wrong template arguments passed into CRTP base classes. This can sometimes happen and not cause an immediate failure when the derived class is, itself, a template. You can end up essentially calling methods on the wrong derived type but a type where many things will appear to "work". To fail fast and with a clear error message we can use a static_assert, but we have to stash that static_assert inside a method body or nested type that won't need to be completed while building the base class. I've tried to pick a reasonably small number of places that seemed like reliably places for this to be instantiated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294271 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 3 years ago
2 changed file(s) with 10 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
388388 return KeyInfoT::getHashValue(Val);
389389 }
390390 static const KeyT getEmptyKey() {
391 static_assert(std::is_base_of::value,
392 "Must pass the derived type to this template!");
391393 return KeyInfoT::getEmptyKey();
392394 }
393395 static const KeyT getTombstoneKey() {
9090
9191 public:
9292 DerivedT operator+(DifferenceTypeT n) const {
93 static_assert(std::is_base_of::value,
94 "Must pass the derived type to this template!");
9395 static_assert(
9496 IsRandomAccess,
9597 "The '+' operator is only defined for random access iterators.");
113115 }
114116
115117 DerivedT &operator++() {
118 static_assert(std::is_base_of::value,
119 "Must pass the derived type to this template!");
116120 return static_cast(this)->operator+=(1);
117121 }
118122 DerivedT operator++(int) {
201205
202206 iterator_adaptor_base() = default;
203207
204 explicit iterator_adaptor_base(WrappedIteratorT u) : I(std::move(u)) {}
208 explicit iterator_adaptor_base(WrappedIteratorT u) : I(std::move(u)) {
209 static_assert(std::is_base_of::value,
210 "Must pass the derived type to this template!");
211 }
205212
206213 const WrappedIteratorT &wrapped() const { return I; }
207214