[PATCH] RFC: fail-fast iterators for DenseMap

Sanjoy Das sanjoy at playingwithpointers.com
Thu Feb 26 22:54:48 PST 2015


In http://reviews.llvm.org/D7931#131003, @ruiu wrote:

> Is it possible to catch an error caused by an expression like m[x] = m[y]?


Do you mean the expression `m[x] =  m[y]` itself is invalid?  Or that it is one more way to "clobber" a `DenseMap` and invalidate all iterators?

> Generally, the last statement v in auto &v = m[x]; m[newkey] = somevalue; v; is invalid because it uses an invalid reference.


That's a harder problem.  The way I'd catch in the snippet you mentioned would be by getting `operator[]` return a wrapper object which would, like the iterator, check its validity on access.  It would also have to be implicitly castable to the `DenseMap`s range type.  However, I don't think any approach will work with `int &v = m[x]; m[y] = foo; use(v)` since we lose any possibility of intercepting the use of `v` as soon as it gets cast to an `int &`.


http://reviews.llvm.org/D7931

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list