Bug 6423 – Garbage is returned from `void main()`

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-08-01T05:06:00Z
Last change time
2015-06-09T05:11:37Z
Keywords
pull, wrong-code
Assigned to
yebblies
Creator
verylonglogin.reg

Comments

Comment #0 by verylonglogin.reg — 2011-08-01T05:06:43Z
No `xor eax,eax` instruction added by dmd v1.069/v2.054 so the program returns garbage: void f(){} void main() { return f(); }
Comment #1 by hsteoh — 2013-08-27T08:16:42Z
Still happens on git HEAD. I'm guessing perhaps the compiler got confused by returning a void function? I'm not sure code like this should be allowed, as it doesn't really make sense to be able to return void (via a return statement) -- nothing is being returned.
Comment #2 by bearophile_hugs — 2013-08-27T08:20:10Z
(In reply to comment #1) > I'm guessing perhaps the compiler got confused by returning a void function? > I'm not sure code like this should be allowed, as it doesn't really make sense > to be able to return void (via a return statement) -- nothing is being > returned. Returning the result of a void function from a void function is accepted by design.
Comment #3 by hsteoh — 2013-08-27T09:42:38Z
OK. Then it's purely just a wrong-code bug.
Comment #4 by ibuclaw — 2013-08-27T10:32:41Z
(In reply to comment #2) > (In reply to comment #1) > > > I'm guessing perhaps the compiler got confused by returning a void function? > > I'm not sure code like this should be allowed, as it doesn't really make sense > > to be able to return void (via a return statement) -- nothing is being > > returned. > > Returning the result of a void function from a void function is accepted by > design. Aye, but 'void main' is implicitly 'int main' - which is a special case in this instance. ;-) All other types of void returns are ok to return garbage.
Comment #5 by yebblies — 2014-08-31T14:45:11Z
Comment #6 by github-bugzilla — 2014-09-12T18:15:44Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/30df9aa10e6b9b32939fc7637f24e72a09534c9d Fix Issue 6423 - Garbage is returned from `void main()` https://github.com/D-Programming-Language/dmd/commit/a80defaf7c0fb16bb223656d35626c5fec658fa4 Merge pull request #3938 from yebblies/issue6423 Issue 6423 - Garbage is returned from `void main()`
Comment #7 by github-bugzilla — 2015-02-18T03:36:44Z