瀏覽代碼

accept "ret" for functions with a return type

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.
Quentin Carbonneaux 9 年之前
父節點
當前提交
fd9c2e045f
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      parse.c

+ 4 - 2
parse.c

@@ -545,10 +545,12 @@ parseline(PState ps)
 			Jrets, Jretd,
 			Jretc, Jret0
 		}[rcls];
-		if (rcls < 5) {
+		if (peek() == Tnl)
+			curb->jmp.type = Jret0;
+		else if (rcls < 5) {
 			r = parseref();
 			if (req(r, R))
-				err("return value expected");
+				err("invalid return value");
 			curb->jmp.arg = r;
 		}
 		goto Close;