[Bug 180] New: DMD accepts a function with a non-void return type but no return statements

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 7 05:19:47 PDT 2006


http://d.puremagic.com/bugzilla/show_bug.cgi?id=180

           Summary: DMD accepts a function with a non-void return type but
                    no return statements
           Product: D
           Version: 0.160
          Platform: PC
               URL: http://www.digitalmars.com/d/statement.html#return
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: smjg at iname.com


The spec for ReturnStatement states:

"At least one return statement is required if the function specifies a return
type that is not void."

However, the compiler fails to honour this requirement, as shown by the most
trivial testcase:

----------
int main() {}
----------

Walter has mentioned that there's a reason to allow paths through a function
that would walk off the end without returning.

However, there is no reason that a function with a non-void return type should
be allowed to have no return statements at all.  The only possible exception is
if the function explicitly throws an exception or assert(false), but if either
of these is to be allowed instead of a single return statement then the spec
would have to be modified to this effect.

As such, the compiler should be reporting an error on such code as the above.


-- 




More information about the Digitalmars-d-bugs mailing list