Thread overview
[Issue 438] New: Compiler allows returning value from void function
Oct 17, 2006
d-bugmail
Oct 17, 2006
d-bugmail
Oct 18, 2006
Brad Roberts
Oct 18, 2006
Sean Kelly
October 17, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=438

           Summary: Compiler allows returning value from void function
           Product: D
           Version: 0.169
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: vlasov@scatt.com


The following code compiles without errors

void foo()
{
        return false;
}

void bar()
{
        return "bar";
}

void main()
{
        foo();
        bar();
}


-- 

October 17, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=438


csantander619@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #1 from csantander619@gmail.com  2006-10-17 08:31 -------
Not a bug, see http://www.digitalmars.com/d/changelog1.html#new0116 "Can now return an expression from a function returning void"


-- 

October 18, 2006
> http://d.puremagic.com/issues/show_bug.cgi?id=438

Can you point to where this is documented in the language spec and maybe some past threads discussing it?  I'm really curious as to the reasons behind the choice.

Thanks,
Brad
October 18, 2006
Brad Roberts wrote:
>  > http://d.puremagic.com/issues/show_bug.cgi?id=438
> 
> Can you point to where this is documented in the language spec and maybe some past threads discussing it?  I'm really curious as to the reasons behind the choice.

I can understand accepting "return void" from a void function, as in C++, but I would expect returning anything else to generate a compile error.