www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 438] New: Compiler allows returning value from void function

reply d-bugmail puremagic.com writes:
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();
}


-- 
Oct 17 2006
parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=438


csantander619 gmail.com changed:

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





Not a bug, see http://www.digitalmars.com/d/changelog1.html#new0116
"Can now return an expression from a function returning void"


-- 
Oct 17 2006
parent reply Brad Roberts <braddr puremagic.com> writes:
 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
Oct 17 2006
parent Sean Kelly <sean f4.ca> writes:
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.
Oct 18 2006