<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Mon, Mar 27, 2017 at 10:20 AM Aaron Ballman via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">aaron.ballman added a comment.<br class="gmail_msg">
<br class="gmail_msg">
In <a href="https://reviews.llvm.org/D31153#711287" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D31153#711287</a>, @dblaikie wrote:<br class="gmail_msg">
<br class="gmail_msg">
> As I mentioned to Craig Topper recently on another review, generally when implementing const and non-const overloads the non-const is implemented in terms of the const overload (& const_casts away const on the result). This ensures no UB if the const overload is called on a truly const object. Even if there aren't any truly const Stmts today, I'd still prefer the code be written so as not to assume they couldn't exist.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
In practice, this is really hard to do because there's no such thing as a const_iterator_cast operation to convert a const_iterator into an iterator, unless you have the underlying container handy. </blockquote><div><br>Seems like it might be feasible to implement. Something along the lines of:<br><br>  struct StmtIterator : ... {<br>    private:<br>      StmtIterator(const ConstStmtIterator& RHS) : StmtIteratorImpl(RHS) { }<br>      friend StmtIterator const_cast(const ConstStmtIterator& RHS) {<br>        return RHS;</div><div>      }<br><br>Something along those lines, I think?<br>(StmtIteratorImpl has a protected ctor that takes a StmtIteratorBase - const or non-const, it doesn't seem to care - so StmtIterator can call that with a ConstStmtIterator and do the conversion?)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Since many of these uses do not have an underlying container (they're often trailing objects), I'm not certain this is practical (though I agree with the reasoning). Suggestions welcome, however.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<a href="https://reviews.llvm.org/D31153" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D31153</a><br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div></div>