aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/bc.c13
-rwxr-xr-xtestsuite/bc.tests5
-rw-r--r--testsuite/bc_misc1.bc4
3 files changed, 11 insertions, 11 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index e5726ca40..6d8e2d991 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -4121,18 +4121,15 @@ static BC_STATUS zbc_parse_return(void)
4121 if (s) RETURN_STATUS(s); 4121 if (s) RETURN_STATUS(s);
4122 4122
4123 t = p->lex; 4123 t = p->lex;
4124 if (t == XC_LEX_NLINE || t == BC_LEX_SCOLON) 4124 if (t == XC_LEX_NLINE || t == BC_LEX_SCOLON || t == BC_LEX_RBRACE)
4125 xc_parse_push(BC_INST_RET0); 4125 xc_parse_push(BC_INST_RET0);
4126 else { 4126 else {
4127 bool paren = (t == BC_LEX_LPAREN); 4127 s = zbc_parse_expr(0);
4128 s = bc_parse_expr_empty_ok(0);
4129 if (s == BC_STATUS_PARSE_EMPTY_EXP) {
4130 xc_parse_push(BC_INST_RET0);
4131 s = zxc_lex_next();
4132 }
4133 if (s) RETURN_STATUS(s); 4128 if (s) RETURN_STATUS(s);
4134 4129
4135 if (!paren || p->lex_last != BC_LEX_RPAREN) { 4130 if (t != BC_LEX_LPAREN // "return EXPR", no ()
4131 || p->lex_last != BC_LEX_RPAREN // example: "return (a) + b"
4132 ) {
4136 s = zbc_POSIX_requires("parentheses around return expressions"); 4133 s = zbc_POSIX_requires("parentheses around return expressions");
4137 if (s) RETURN_STATUS(s); 4134 if (s) RETURN_STATUS(s);
4138 } 4135 }
diff --git a/testsuite/bc.tests b/testsuite/bc.tests
index 7795183a7..0a8222be6 100755
--- a/testsuite/bc.tests
+++ b/testsuite/bc.tests
@@ -103,6 +103,11 @@ testing "bc for (;;) {break}" \
103 "2\n9\n" \ 103 "2\n9\n" \
104 "" "for (;;) {2;break}; 9" 104 "" "for (;;) {2;break}; 9"
105 105
106testing "bc define {return}" \
107 "bc" \
108 "0\n9\n" \
109 "" "define w() {return}\nw();9"
110
106testing "bc define auto" \ 111testing "bc define auto" \
107 "bc" \ 112 "bc" \
108 "8\n9\n" \ 113 "8\n9\n" \
diff --git a/testsuite/bc_misc1.bc b/testsuite/bc_misc1.bc
index 7e9d96604..f666d701a 100644
--- a/testsuite/bc_misc1.bc
+++ b/testsuite/bc_misc1.bc
@@ -4,9 +4,7 @@ define x(x) {
4define y() { 4define y() {
5 return; 5 return;
6} 6}
7define z() { 7define z() {return}
8 return ();
9}
10scale = 0 8scale = 0
11x=2 9x=2
12x[0]=3 10x[0]=3