[Issue 1977] Relax warnings for implicit narrowing conversions caused by promotions
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Nov 24 12:48:23 PST 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1977
------- Comment #15 from andrei at metalanguage.com 2008-11-24 14:48 -------
(In reply to comment #14)
> (In reply to comment #13)
> > (In reply to comment #12)
> > > (In reply to comment #10)
> > > > c += 'A' - 'a';
> > > >
> > > > Casting seems too strict a requirement in these types of situations. I can't
> > > > imagine that anyone has a positive experience with these warnings, most are
> > > > just going to grumble, then insert the cast without thinking about it.
> > >
> > > Notice that in the particular example you mention, the code does go through
> > > because it uses +=.
> >
> > Wow, that surprises me.
> >
> > c = c + c should be equivalent to c += c;
> >
> > So right there, either both should be invalid, or neither should. Both have an
> > equal chance of overflow.
>
> It shouldn't be that surprising, particularly considering that Java and C# obey
> the same rules. The correct equivalence is that c = c + c is really c =
> cast(typeof(c))(c + c).
I meant c += c is equivalent to cast(typeof(c))(c + c).
--
More information about the Digitalmars-d-bugs
mailing list