<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    However, the end pointer can never be less than the begin pointer,
    so you can safely cast the ptrdiff_t result to size_t.  Restricting
    it to PTRDIFF_MAX seems unnecessarily restrictive.<br>
    <br>
    <div class="moz-cite-prefix">On 02/16/2015 03:30 AM, Mikael Persson
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAObjFXg9QS9p0oNcUqj9tUpi97smDnjbbweoycJw8PWE4s2tHw@mail.gmail.com"
      type="cite">
      <div dir="ltr">Hi François,
        <div><br>
        </div>
        <div>I think you are absolutely correct. And this should
          definitely be addressed. I think the best would be for you to
          file a bug report on both libc++ and libstdc++.</div>
        <div><br>
        </div>
        <div>Here are a few additional things I would point out:</div>
        <div><br>
        </div>
        <div>Note, however, that this only affects vectors with elements
          of size 1 or less (like vector of bool), because any other
          type, of size 2 or above, can never have a pointer difference
          that would overflow ptrdiff_t. So, we are really only talking
          about char, unsigned char, bool, and empty classes.</div>
        <div><br>
        </div>
        <div>I see only one sensible option to address this, which is to
          restrict max_size() to output the max positive value of
          ptrdiff_t. Something like this:</div>
        <div><br>
        </div>
        <div>    size_type max_size() const noexcept {</div>
        <div>      return ( PTRDIFF_MAX < /* alloc max-size */ ?
          PTRDIFF_MAX : /* alloc max-size */ );</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>It could also be conditional upon sizeof(T) such that this
          extra step is only done for elements of size 1.<br>
        </div>
        <div><br>
        </div>
        <div>The alternative of accounting for overflow on the
          calculation of size() would not only have undue overhead on
          size(), but it would also imply the same precaution be taken
          everywhere else (in iterators, in most mutating member
          functions, etc..). And I'm also not sure that this would be
          standard conforming since the difference_type would no longer
          be able to represent all iterator differences.</div>
        <div><br>
        </div>
        <div>Cheers,</div>
        <div>Mikael.</div>
        <div>
          <div class="gmail_extra">
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a>
</pre>
    </blockquote>
    <br>
    <div class="moz-signature">-- <br>
      <pre class="moz-signature" cols="256">Dick Hadsell                      203-992-6320  Fax: 203-992-6001
Reply-to:                       <a class="moz-txt-link-abbreviated" href="mailto:hadsell@blueskystudios.com">hadsell@blueskystudios.com</a>
Blue Sky Studios                <a class="moz-txt-link-freetext" href="http://www.blueskystudios.com">http://www.blueskystudios.com</a>
1 American Lane, Greenwich, CT 06831-2560
</pre>
    </div>
  </body>
</html>