[Issue 3160] ICE(cgcod.c 1511) returning string from void main, D1 only

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 15 08:44:17 PDT 2009


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


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

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


--- Comment #2 from Don <clugdbug at yahoo.com.au> 2009-09-15 08:44:16 PDT ---
ROOT CAUSE: The logic for inserting a "return 0" at the end of a void main, and
the logic for evaluating the return expression in a void function, interact
incorrectly. The case where BOTH these things need to happen was missing. BTW,
this is probably wrong in D2 as well.


PATCH: statement.c, last lines of ReturnStatement::semantic (around line 2891):

-    if (exp && tbret->ty == Tvoid && !fd->isMain())
+    if (exp && tbret->ty == Tvoid && !implicit0)
    {
    /* Replace:
     *    return exp;
     * with:
     *    exp; return;
     */
    Statement *s = new ExpStatement(loc, exp);
    loc = 0;
+    if (fd->isMain()) exp = new IntegerExp(0);
+    else
        exp = NULL;
    return new CompoundStatement(loc, s, this);
    }
    return this;
}

-- 
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