<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Mar 22, 2017 at 1:23 PM Dmitry Babokin via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">Reid,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">std::prev() works, though IMHO increment/decrement are more conventional way (I'm not saying better) to work with iterators.</div></div></blockquote><div><br>To be clear, increment/decrement do work with pointers, but the specific case here is that they don't work with rvalue pointers. So this works:<br><br>iterator I = func();</div><div>--I;<br><br>but this does not:<br><br> --func()<br><br>^ is not guaranteed to work with all iterators (pointers being the obvious example - which would be true in a simple implementation of std::vector). It only happens to work with non-trivial iterators, where increment/decrement are implemented by operator overloads, rather than naturally by a pointer.<br><br>That's why std::next/prev exist - to help with this case when writing portable/general code.<br><br>Actually, I suppose we could defensively disable this for non-trivial iterators by deleting rvalue overloads of the increment/decrement operators...<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I have no problem fixing code on my side, I'm just bringing your attention that code like this is broken. If your judgement is to keep it the way it is now, I'm ok with it.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Thanks.</div></div><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Dmitry.</div></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On Wed, Mar 22, 2017 at 1:20 PM, Reid Kleckner <span dir="ltr" class="gmail_msg"><<a href="mailto:rnk@google.com" class="gmail_msg" target="_blank">rnk@google.com</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><span class="gmail_msg">On Wed, Mar 22, 2017 at 1:12 PM, Dmitry Babokin <span dir="ltr" class="gmail_msg"><<a href="mailto:babokin@gmail.com" class="gmail_msg" target="_blank">babokin@gmail.com</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><span class="gmail_msg"><div class="gmail_msg">Correct, I mean exactly this. Though &* is not important in this case.<br class="gmail_msg"></div></span><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">This code doesn't work anymore, as arg_iterator is defined differently now: <a href="https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Function.h#L57" class="gmail_msg" target="_blank">https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Function.h#L57</a></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I get an error when I'm using pre-decrement operator:</div><div class="gmail_msg"><div class="gmail_msg">error: expression is not assignable</div><div class="gmail_msg"> --f->arg_end();</div></div></div></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></span><div class="gmail_msg">Today's arg_iterator is now just an Argument*, which is the world's simplest iterator. The '--f->arg_end()' snippet only compiled before this change because we used to use fancy ilist iterators which had overloaded decrement operators.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I don't think we should make a wrapper pointer iterator type just to make old code like this compile.</div></div></div></div>
</blockquote></div><br class="gmail_msg"></div>
_______________________________________________<br class="gmail_msg">
LLVM Developers mailing list<br class="gmail_msg">
<a href="mailto:llvm-dev@lists.llvm.org" class="gmail_msg" target="_blank">llvm-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="gmail_msg">
</blockquote></div></div>