digitalmars.D.bugs - compiler does not complain no required return value
- z gg.com (9/9) Aug 26 2005 Instead, the generated binary will abort at run-time and give misleading
- z gg.com (2/9) Aug 26 2005
- Derek Parnell (11/22) Aug 26 2005 This is not a bug.
- Stewart Gordon (15/30) Aug 26 2005 Nonsense.
- Derek Parnell (7/31) Aug 26 2005 But 'required' by what? I suspect it is the run-time application that
- Stewart Gordon (15/24) Aug 26 2005 The D language. And hence any correct D compiler.
- Dave (12/36) Aug 26 2005 As long as your not talking about the compiler checking every possible p...
- z gg.com (3/7) Aug 26 2005 *EVEN* in that case, a more meaningfull message should be generated, e.g...
- Mike Parker (8/17) Aug 26 2005 When you compile with -w the compiler will let you know of missing
Instead, the generated binary will abort at run-time and give misleading message: int f() { return 0; // gdc Error: AssertError Failure rtn.d(3); dmd Aborted } int main(char[][] args) { f(); return 0; }
Aug 26 2005
int f() { // return 0; // gdc Error: AssertError Failure rtn.d(3); dmd Aborted---^^ need to comment out line 3, to see the error.} int main(char[][] args) { f(); return 0; }
Aug 26 2005
On Fri, 26 Aug 2005 07:18:51 +0000 (UTC), z gg.com wrote:Instead, the generated binary will abort at run-time and give misleading message: int f() { return 0; // gdc Error: AssertError Failure rtn.d(3); dmd Aborted } int main(char[][] args) { f(); return 0; }This is not a bug. If you define a routine to return a value, but you don't actually return anything, the function will crash at run time. The compiler does not attempt to detect this situation, instead it generates a hidden assert at the end of the function. -- Derek (skype: derek.j.parnell) Melbourne, Australia 26/08/2005 6:04:14 PM
Aug 26 2005
Derek Parnell wrote:On Fri, 26 Aug 2005 07:18:51 +0000 (UTC), z gg.com wrote:[implemented correction]Instead, the generated binary will abort at run-time and give misleading message: int f() {Nonsense. http://www.digitalmars.com/d/statement.html#return "At least one return statement is required if the function specifies a return type that is not void." Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.// return 0; // gdc Error: AssertError Failure rtn.d(3); dmd Aborted } int main(char[][] args) { f(); return 0; }This is not a bug.
Aug 26 2005
On Fri, 26 Aug 2005 12:09:41 +0100, Stewart Gordon wrote:Derek Parnell wrote:But 'required' by what? I suspect it is the run-time application that requires it rather than the compiler itself. -- Derek Parnell Melbourne, Australia 27/08/2005 12:27:36 AMOn Fri, 26 Aug 2005 07:18:51 +0000 (UTC), z gg.com wrote:[implemented correction]Instead, the generated binary will abort at run-time and give misleading message: int f() {Nonsense. http://www.digitalmars.com/d/statement.html#return "At least one return statement is required if the function specifies a return type that is not void."// return 0; // gdc Error: AssertError Failure rtn.d(3); dmd Aborted } int main(char[][] args) { f(); return 0; }This is not a bug.
Aug 26 2005
Derek Parnell wrote:On Fri, 26 Aug 2005 12:09:41 +0100, Stewart Gordon wrote:<snip>The D language. And hence any correct D compiler.http://www.digitalmars.com/d/statement.html#return "At least one return statement is required if the function specifies a return type that is not void."But 'required' by what?I suspect it is the run-time application that requires it rather than the compiler itself.If that's so, then you could equally state that "The body of all asserts is required to evaluate to non-zero." By which the average person is likely to interpret what? Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Aug 26 2005
In article <dengj7$1is0$1 digitaldaemon.com>, Stewart Gordon says...Derek Parnell wrote:As long as your not talking about the compiler checking every possible path for a return statement (something that probably no compiler has ever gotten 100% right anyhow), then I would have to agree that the compiler should at least check for a return statement inside the body of a function. Take a look in the archives - IMO, Walter has good reasoning for the compiler not forcing a return for all paths. But checking that a function actually has a valid return statement if it's expected to return something should be part of the reference compiler because 1) it will save programmers a lot of "oopses", 2) it's gotta be readily do-able to verify 100% of the time and 3) the spec. above really is unequivocal on the matter. - DaveOn Fri, 26 Aug 2005 12:09:41 +0100, Stewart Gordon wrote:<snip>The D language. And hence any correct D compiler.http://www.digitalmars.com/d/statement.html#return "At least one return statement is required if the function specifies a return type that is not void."But 'required' by what?I suspect it is the run-time application that requires it rather than the compiler itself.If that's so, then you could equally state that "The body of all asserts is required to evaluate to non-zero."By which the average person is likely to interpret what? Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Aug 26 2005
return 0; // gdc Error: AssertError Failure rtn.d(3); dmd AbortedThe compiler does not attempt to detect this situation, instead it generates a hidden assert at the end of the function.*EVEN* in that case, a more meaningfull message should be generated, e.g. "NoReturnValueAssertError" Which is much more human readable.
Aug 26 2005
z gg.com wrote:return 0; // gdc Error: AssertError Failure rtn.d(3); dmd Aborted*EVEN* in that case, a more meaningfull message should be generated, e.g. "NoReturnValueAssertError" Which is much more human readable.When you compile with -w the compiler will let you know of missing return statements: end of function. Walter added this as a concession after much debate over the default behaviour. So if you want to catch these cases at compile time, use -w and be happy.
Aug 26 2005