This happens to be needed for C. The standard mandates that a return value is used if the caller uses it. Surprisingly, if the return "value" is not used, the callee can use "return;". A better solution is to add an "undef" value and return it, "undef" would also have other use cases for compiling C.
Showing the changes to parse.c (1 of 1 file). Show all
Unified · Split
| @@ -545,10 +545,12 @@ parseline(PState ps) · 544 unmodified lines | ||
| 545 | 545 | Jrets, Jretd, |
| 546 | 546 | Jretc, Jret0 |
| 547 | 547 | }[rcls]; |
| 548 | − if (rcls < 5) { | |
| 548 | + if (peek() == Tnl) | |
| 549 | + curb->jmp.type = Jret0; | |
| 550 | + else if (rcls < 5) { | |
| 549 | 551 | r = parseref(); |
| 550 | 552 | if (req(r, R)) |
| 551 | − err("return value expected"); | |
| 553 | + err("invalid return value"); | |
| 552 | 554 | curb->jmp.arg = r; |
| 553 | 555 | } |
| 554 | 556 | goto Close; |