Mercurial > projects > ldc
diff dmd/cast.c @ 846:bc982f1ad106
Merged DMD 1.037 frontend
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sat, 13 Dec 2008 13:15:31 +0100 |
parents | a26b0c5d5942 |
children | b30fe7e1dbb9 |
line wrap: on
line diff
--- a/dmd/cast.c Sat Dec 13 06:48:00 2008 +0100 +++ b/dmd/cast.c Sat Dec 13 13:15:31 2008 +0100 @@ -33,9 +33,10 @@ { //printf("implicitCastTo(%s) => %s\n", type->toChars(), t->toChars()); if (implicitConvTo(t)) - { + { TY tyfrom = type->toBasetype()->ty; + TY tyto = t->toBasetype()->ty; if (global.params.warnings && - Type::impcnvWarn[type->toBasetype()->ty][t->toBasetype()->ty] && + Type::impcnvWarn[tyfrom][tyto] && op != TOKint64) { Expression *e = optimize(WANTflags | WANTvalue); @@ -43,8 +44,24 @@ if (e->op == TOKint64) return e->implicitCastTo(sc, t); - warning("%s: implicit conversion of expression (%s) of type %s to %s can cause loss of data", - loc.toChars(), toChars(), type->toChars(), t->toChars()); + if (tyfrom == Tint32 && + (op == TOKadd || op == TOKmin || + op == TOKand || op == TOKor || op == TOKxor) + ) + { + /* This is really only a semi-kludge fix, + * we really should look at the operands of op + * and see if they are narrower types. + * For example, b=b|b and b=b|7 and s=b+b should be allowed, + * but b=b|i should be an error. + */ + ; + } + else + { + warning("%s: implicit conversion of expression (%s) of type %s to %s can cause loss of data", + loc.toChars(), toChars(), type->toChars(), t->toChars()); + } } #if DMDV2 if (match == MATCHconst && t == type->constOf())