comparison dmd2/cast.c @ 847:356e65836fb5

Merged DMD 2.021 frontend. Removed generated files from dmd/dmd2 dirs.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sat, 13 Dec 2008 16:14:37 +0100
parents f04dde6e882c
children 638d16625da2
comparison
equal deleted inserted replaced
846:bc982f1ad106 847:356e65836fb5
33 { 33 {
34 //printf("Expression::implicitCastTo(%s of type %s) => %s\n", toChars(), type->toChars(), t->toChars()); 34 //printf("Expression::implicitCastTo(%s of type %s) => %s\n", toChars(), type->toChars(), t->toChars());
35 35
36 MATCH match = implicitConvTo(t); 36 MATCH match = implicitConvTo(t);
37 if (match) 37 if (match)
38 { 38 { TY tyfrom = type->toBasetype()->ty;
39 TY tyto = t->toBasetype()->ty;
39 if (global.params.warnings && 40 if (global.params.warnings &&
40 Type::impcnvWarn[type->toBasetype()->ty][t->toBasetype()->ty] && 41 Type::impcnvWarn[tyfrom][tyto] &&
41 op != TOKint64) 42 op != TOKint64)
42 { 43 {
43 Expression *e = optimize(WANTflags | WANTvalue); 44 Expression *e = optimize(WANTflags | WANTvalue);
44 45
45 if (e->op == TOKint64) 46 if (e->op == TOKint64)
46 return e->implicitCastTo(sc, t); 47 return e->implicitCastTo(sc, t);
47 48
48 warning("%s: implicit conversion of expression (%s) of type %s to %s can cause loss of data", 49 if (tyfrom == Tint32 &&
49 loc.toChars(), toChars(), type->toChars(), t->toChars()); 50 (op == TOKadd || op == TOKmin ||
51 op == TOKand || op == TOKor || op == TOKxor)
52 )
53 {
54 /* This is really only a semi-kludge fix,
55 * we really should look at the operands of op
56 * and see if they are narrower types.
57 * For example, b=b|b and b=b|7 and s=b+b should be allowed,
58 * but b=b|i should be an error.
59 */
60 ;
61 }
62 else
63 {
64 warning("%s: implicit conversion of expression (%s) of type %s to %s can cause loss of data",
65 loc.toChars(), toChars(), type->toChars(), t->toChars());
66 }
50 } 67 }
51 #if DMDV2 68 #if DMDV2
52 if (match == MATCHconst && t == type->constOf()) 69 if (match == MATCHconst && t == type->constOf())
53 { 70 {
54 Expression *e = copy(); 71 Expression *e = copy();
1040 else 1057 else
1041 f = f2; 1058 f = f2;
1042 } 1059 }
1043 } 1060 }
1044 if (f) 1061 if (f)
1045 { f->tookAddressOf = 1; 1062 { f->tookAddressOf++;
1046 SymOffExp *se = new SymOffExp(loc, f, 0, 0); 1063 SymOffExp *se = new SymOffExp(loc, f, 0, 0);
1047 se->semantic(sc); 1064 se->semantic(sc);
1048 // Let SymOffExp::castTo() do the heavy lifting 1065 // Let SymOffExp::castTo() do the heavy lifting
1049 return se->castTo(sc, t); 1066 return se->castTo(sc, t);
1050 } 1067 }
1203 else 1220 else
1204 { 1221 {
1205 e = new SymOffExp(loc, f, 0); 1222 e = new SymOffExp(loc, f, 0);
1206 e->type = t; 1223 e->type = t;
1207 } 1224 }
1208 f->tookAddressOf = 1; 1225 f->tookAddressOf++;
1209 return e; 1226 return e;
1210 } 1227 }
1211 } 1228 }
1212 } 1229 }
1213 e = Expression::castTo(sc, t); 1230 e = Expression::castTo(sc, t);
1244 f = func->overloadExactMatch(tb->nextOf()); 1261 f = func->overloadExactMatch(tb->nextOf());
1245 if (f) 1262 if (f)
1246 { int offset; 1263 { int offset;
1247 if (f->tintro && f->tintro->nextOf()->isBaseOf(f->type->nextOf(), &offset) && offset) 1264 if (f->tintro && f->tintro->nextOf()->isBaseOf(f->type->nextOf(), &offset) && offset)
1248 error("%s", msg); 1265 error("%s", msg);
1249 f->tookAddressOf = 1; 1266 f->tookAddressOf++;
1250 e = new DelegateExp(loc, e1, f); 1267 e = new DelegateExp(loc, e1, f);
1251 e->type = t; 1268 e->type = t;
1252 return e; 1269 return e;
1253 } 1270 }
1254 if (func->tintro) 1271 if (func->tintro)
1258 e = Expression::castTo(sc, t); 1275 e = Expression::castTo(sc, t);
1259 } 1276 }
1260 else 1277 else
1261 { int offset; 1278 { int offset;
1262 1279
1263 func->tookAddressOf = 1; 1280 func->tookAddressOf++;
1264 if (func->tintro && func->tintro->nextOf()->isBaseOf(func->type->nextOf(), &offset) && offset) 1281 if (func->tintro && func->tintro->nextOf()->isBaseOf(func->type->nextOf(), &offset) && offset)
1265 error("%s", msg); 1282 error("%s", msg);
1266 e = copy(); 1283 e = copy();
1267 e->type = t; 1284 e->type = t;
1268 } 1285 }