comparison 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
comparison
equal deleted inserted replaced
845:d128381e086e 846:bc982f1ad106
31 31
32 Expression *Expression::implicitCastTo(Scope *sc, Type *t) 32 Expression *Expression::implicitCastTo(Scope *sc, Type *t)
33 { 33 {
34 //printf("implicitCastTo(%s) => %s\n", type->toChars(), t->toChars()); 34 //printf("implicitCastTo(%s) => %s\n", type->toChars(), t->toChars());
35 if (implicitConvTo(t)) 35 if (implicitConvTo(t))
36 { 36 { TY tyfrom = type->toBasetype()->ty;
37 TY tyto = t->toBasetype()->ty;
37 if (global.params.warnings && 38 if (global.params.warnings &&
38 Type::impcnvWarn[type->toBasetype()->ty][t->toBasetype()->ty] && 39 Type::impcnvWarn[tyfrom][tyto] &&
39 op != TOKint64) 40 op != TOKint64)
40 { 41 {
41 Expression *e = optimize(WANTflags | WANTvalue); 42 Expression *e = optimize(WANTflags | WANTvalue);
42 43
43 if (e->op == TOKint64) 44 if (e->op == TOKint64)
44 return e->implicitCastTo(sc, t); 45 return e->implicitCastTo(sc, t);
45 46
46 warning("%s: implicit conversion of expression (%s) of type %s to %s can cause loss of data", 47 if (tyfrom == Tint32 &&
47 loc.toChars(), toChars(), type->toChars(), t->toChars()); 48 (op == TOKadd || op == TOKmin ||
49 op == TOKand || op == TOKor || op == TOKxor)
50 )
51 {
52 /* This is really only a semi-kludge fix,
53 * we really should look at the operands of op
54 * and see if they are narrower types.
55 * For example, b=b|b and b=b|7 and s=b+b should be allowed,
56 * but b=b|i should be an error.
57 */
58 ;
59 }
60 else
61 {
62 warning("%s: implicit conversion of expression (%s) of type %s to %s can cause loss of data",
63 loc.toChars(), toChars(), type->toChars(), t->toChars());
64 }
48 } 65 }
49 #if DMDV2 66 #if DMDV2
50 if (match == MATCHconst && t == type->constOf()) 67 if (match == MATCHconst && t == type->constOf())
51 { 68 {
52 Expression *e = copy(); 69 Expression *e = copy();