[Issue 3553] ICE when a function argument defaults to __LINE__

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 26 23:55:25 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3553


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #2 from Don <clugdbug at yahoo.com.au> 2009-11-26 23:55:23 PST ---
There are two issues. One is that this use of __LINE__ is a very special case.

The code in Parser::parseDefaultInitExp() in parse.c is unlikely to be correct
-- it only treats a default of __LINE__ specially; __LINE__+0 does NOT become a
LineInitExp.

But, without changing that, the immediate problem is in expression.c,
functionParameters(), around line 670.

The lineInitExp only gets resolved if it's unaltered. But, it might
have been implicitly cast. This patch fixes that.
A more complete fix would change parse.c to allow arbitrary use of __LINE__,
and to resolve recursively in expression.c looking for LineInitExp's. But
that's a pretty obscure feature; this patch is enough to fix the ICE.

Index: expression.c
===================================================================
--- expression.c    (revision 267)
+++ expression.c    (working copy)
@@ -667,7 +667,13 @@
         }
         arg = p->defaultArg;
 #if DMDV2
-        if (arg->op == TOKdefault)
+        if (arg->op == TOKcast && ((CastExp*)arg)->e1->op == TOKdefault)
+        {   // The default value may have been implicitly cast
+            arg = arg->copy();
+            CastExp * def = (CastExp*)arg;
+            def->e1 = ((DefaultInitExp *)(def->e1))->resolve(loc, sc);
+        }
+        else if (arg->op == TOKdefault)
         {   DefaultInitExp *de = (DefaultInitExp *)arg;
             arg = de->resolve(loc, sc);
         }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list