On Wed, Oct 22, 2008 at 12:58 PM, Kasper Lund <[EMAIL PROTECTED]> wrote:

>
> Isn't it a valid warning?


Nope.


> Why is it okay to throw away some of the
> bits from src?


Because we only get there if we know the resulting string is ASCII only.

I could have solved it by putting an

if (sizeof(sinkchar) == 2)

around the call to CopyChars in WriteToFlat in two places.  WriteToFlat is
currently not called in that configuration.  But that would preclude using
WriteToFlat to generate ASCII strings from strings that were using 16 bit
representation but which had been checked for non-ASCII characters.  We
don't use that at the moment, but it seems like an OK thing to do.  Also it
spreads the ugliness around more.


> Does your change lint?


Yes.


> Can't you use a static_cast
> instead of the C-style cast?


It turns out I can.

I removed the comment which seemed unnecessarily verbose.


>
>
> On Wed, Oct 22, 2008 at 12:47 PM,  <[EMAIL PROTECTED]> wrote:
> > Reviewers: Kasper Lund,
> >
> > Description:
> > Fix warning from Windows about loss of data in cast-less assignment.
> >
> > Please review this at http://codereview.chromium.org/7865
> >
> > SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
> >
> > Affected files:
> >  M     src/utils.h
> >
> >
> > Index: src/utils.h
> > ===================================================================
> > --- src/utils.h (revision 549)
> > +++ src/utils.h (working copy)
> > @@ -448,7 +448,11 @@
> >  template <typename sourcechar, typename sinkchar>
> >  static inline void CopyChars(sinkchar* dest, const sourcechar* src, int
> > chars) {
> >   while (chars--) {
> > -    *dest++ = *src++;
> > +    // We have to have a cast here, otherwise MSVC complains about a
> > possible
> > +    // loss of data when sourcechar is 16 bit and sinkchar is 8 bit.
>  But
> > we
> > +    // can't have a reinterpret cast because gcc doesn't like a
> > reinterpret_cast
> > +    // that doesn't change the type.
> > +    *dest++ = (sinkchar)(*src++);
> >   }
> >  }
> >
> >
> >
> >
>
> >
>


-- 
Erik Corry, Software Engineer
Google Denmark ApS.  CVR nr. 28 86 69 84
c/o Philip & Partners, 7 Vognmagergade, P.O. Box 2227, DK-1018 Copenhagen K,
Denmark.

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to