[Libreoffice] signed/unsigned comparison (was: [PATCH] Replace SvULongs with vector and code clean up part 1)

Lubos Lunak l.lunak at suse.cz
Wed Aug 10 03:31:40 PDT 2011


On Tuesday 09 of August 2011, Stephan Bergmann wrote:
> On Aug 9, 2011, at 5:15 PM, Lubos Lunak wrote:
> > namespace lostd // or just no namespace at all, any other 'list' class is
> > unlikely
> > {
> > template< ... >
> > class list : public ::std::list< ... >
> > {
> > ...
> > int size() const { return ::std::list< ... >::size(); } // plus possibly
> > checks here, but somehow doubt there are many cases, if any, where one
> > would have a list with more than 2E9 items
> > ...
> > };
> >
> > This class is technically still also std::list, so it should be a drop-in
> > replacement for all cases. And IMO a much nicer solution than
> > people "randomly" adding casts all over the codebase.
>
> Technically, lostd::list is no longer a container, as it violates the
> requirement that the return type of size() is size_type.  (And if you
> redefine size_type as int, as you should do anyway in the above sketch, it
> violates the requirement that size_type is an unsigned integral type.) 

 Do you realize that as long as the list does not contain 2E9 items, which it 
does not, this does not matter at all?

> Really, I would not try to outsmart the specification---even if the
> specification is far from beautiful.

 Right, doing things properly, for whatever definition of 'properly', is more 
important than anything else. That's how OOo has always been developed and 
that's why we now have a clean, easy to understand and elegant codebase. Oh, 
wait.

> From my experience, I consider the problem of "randomly added casts" as not
> that severe, anyway.  The best fix for the code in question would probably
> be if "indexing types" like the type of nEntry were std::size_t to begin
> with.

 You can never do without signed types, so as long as there's a single 
unsigned type, there always will be mixing.

-- 
 Lubos Lunak
 l.lunak at suse.cz


More information about the LibreOffice mailing list