diff 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
line wrap: on
line diff
--- a/dmd2/cast.c	Sat Dec 13 13:15:31 2008 +0100
+++ b/dmd2/cast.c	Sat Dec 13 16:14:37 2008 +0100
@@ -35,9 +35,10 @@
 
     MATCH match = implicitConvTo(t);
     if (match)
-    {
+    {	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);
@@ -45,8 +46,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())
@@ -1042,7 +1059,7 @@
 		}
 	    }
 	    if (f)
-	    {	f->tookAddressOf = 1;
+	    {	f->tookAddressOf++;
 		SymOffExp *se = new SymOffExp(loc, f, 0, 0);
 		se->semantic(sc);
 		// Let SymOffExp::castTo() do the heavy lifting
@@ -1205,7 +1222,7 @@
 			e = new SymOffExp(loc, f, 0);
 			e->type = t;
 		    }
-		    f->tookAddressOf = 1;
+		    f->tookAddressOf++;
 		    return e;
 		}
 	    }
@@ -1246,7 +1263,7 @@
 		{   int offset;
 		    if (f->tintro && f->tintro->nextOf()->isBaseOf(f->type->nextOf(), &offset) && offset)
 			error("%s", msg);
-		    f->tookAddressOf = 1;
+		    f->tookAddressOf++;
 		    e = new DelegateExp(loc, e1, f);
 		    e->type = t;
 		    return e;
@@ -1260,7 +1277,7 @@
     else
     {	int offset;
 
-	func->tookAddressOf = 1;
+	func->tookAddressOf++;
 	if (func->tintro && func->tintro->nextOf()->isBaseOf(func->type->nextOf(), &offset) && offset)
 	    error("%s", msg);
 	e = copy();