[Issue 3574] post-condition in void main() is not evaluated if there is no return statement
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 28 00:29:31 PST 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3574
Don <clugdbug at yahoo.com.au> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
Summary|post-condition is not |post-condition in void
|evaluated if there is no |main() is not evaluated if
|return statement |there is no return
| |statement
--- Comment #2 from Don <clugdbug at yahoo.com.au> 2010-01-28 00:29:30 PST ---
This is a very obscure bug; it's of interest for educational purposes only.
Only void main() is affected, and it's because the return 0; needs to be added
AFTER the invariant is processed, not before.
This patch (against DMD2, svn 356) just moves the return 0; insertion slightly
later in FuncDeclaration::semantic3().
Index: func.c
===================================================================
--- func.c (revision 356)
+++ func.c (working copy)
@@ -1287,16 +1287,8 @@
int offend = blockexit & BEfallthru;
#endif
- if (type->nextOf()->ty == Tvoid)
+ if (type->nextOf()->ty != Tvoid)
{
- if (offend && isMain())
- { // Add a return 0; statement
- Statement *s = new ReturnStatement(0, new IntegerExp(0));
- fbody = new CompoundStatement(0, fbody, s);
- }
- }
- else
- {
if (offend)
{ Expression *e;
#if DMDV1
@@ -1462,8 +1454,17 @@
}
ReturnStatement *s = new ReturnStatement(0, e);
a->push(s);
- }
+ }
}
+#if DMDV2
+ int blockexit = fbody ? fbody->blockExit() : BEfallthru;
+ int offend = blockexit & BEfallthru;
+#endif
+ if (offend && isMain() && type->nextOf()->ty == Tvoid)
+ { // For void main(), add a 'return 0' statement
+ ReturnStatement *s = new ReturnStatement(0, new IntegerExp(0));
+ a->push(s);
+ }
fbody = new CompoundStatement(0, a);
#if DMDV2
--
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