<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Feb 14, 2014, at 4:31 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br><div><blockquote type="cite"><div class="gmail_extra"><div class="gmail_quote">On Fri, Feb 14, 2014 at 4:21 PM, Marshall Clow <span dir="ltr"><<a href="mailto:mclow.lists@gmail.com" target="_blank">mclow.lists@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;">Users can write<br>        for(sregex_iterator i(s.begin(), s.end(), regex("meow")), end; i != end; ++i)<br><br>binding a temporary regex to const regex& and storing a pointer to it.<br>This will compile silently, triggering undefined behavior at runtime.<br><br>Fixing this involves defining constructors for the various regex iterator types from rvalue regexes, and then marking them as “deleted”.<br>And tests.<br><br></blockquote></div></div></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><div dir="ltr">Would this break (what I assume is) correct code doing things like:<br><br>std::find(sregex_iterator(s.begin(), s.end(), regex("meow")), end, "foo”);<br></div></blockquote><div><br></div>Yes, but while that code is technically “correct”, it’s not useful.</div><div><br></div><div>The return value from find is going to be an iterator that “points” into a destructed regex.</div><div>As soon as you use it for anything, you’re (hopefully) going to go boom.</div><div><br></div><div>The “fix” for this is easy.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>regex meow { “meow” };</div><div><span class="Apple-tab-span" style="white-space:pre">       </span>std::find(sregex_iterator(s.begin(), s.end(), meow), end, "foo”);</div><div><br></div><div>Now you can control the lifetime of the regex, and make sure that it doesn’t get destroyed too early.</div><div><br></div><div>For those following along at home, the standard issue (which was adopted for C++14) is here:</div><div><span class="Apple-tab-span" style="white-space:pre">      </span><a href="http://cplusplus.github.io/LWG/lwg-active.html#2332">http://cplusplus.github.io/LWG/lwg-active.html#2332</a></div><div><br></div><div>and a closely related one (also part of the C++14 standard):</div><div><span class="Apple-tab-span" style="white-space: pre;">    </span><a href="http://cplusplus.github.io/LWG/lwg-active.html#2329">http://cplusplus.github.io/LWG/lwg-active.html#2329</a></div><div><br></div><div>Here’s a revised patch that covers both of them.</div><div><br></div><div>— Marshall</div><div><br></div><div><blockquote type="cite"><div class="gmail_extra"><div class="gmail_quote"></div></div>
</blockquote></div></body></html>