[cfe-dev] libc++: max_size() of a std::vector

François Fayard fayard.francois at icloud.com
Tue Feb 17 09:33:37 PST 2015


Hi Dick,

I disagree. It should be restricted to PTRDIFF_MAX if you want to be compliant with any C++11 compiler.

If the difference of the 2 pointers does not fit into std::ptrdiff_t, you run into undefined behaviour. Nevertheless, I am quite sure most compilers will give the “expected result” for static_cast<std::size_t>(end_ - begin_). But it should be considered as luck, not as something certified by the standard.

François


> On 17 Feb 2015, at 17:28, Richard Hadsell <hadsell at blueskystudios.com> wrote:
> 
> 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.
> Dick Hadsell			203-992-6320  Fax: 203-992-6001
> Reply-to:			hadsell at blueskystudios.com <mailto:hadsell at blueskystudios.com>
> Blue Sky Studios                http://www.blueskystudios.com <http://www.blueskystudios.com/>
> 1 American Lane, Greenwich, CT 06831-2560

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150217/417b8c3e/attachment.html>


More information about the cfe-dev mailing list