Branch: Tag:

2017-09-09

2017-09-09 10:36:40 by Marcus Comstedt <marcus@mc.pp.se>

Compiler: Allow return void expression from void function

Fixes [LysLysKOM 22188815].

3738:       case F_RETURN:    if (!CAR(n) || (CAR(n)->type == void_type_string)) { -  yywarning("Returning a void expression. Converted to zero."); +     if (!CAR(n)) {    _CAR(n) = mkintnode(0);    copy_pike_type(n->type, CAR(n)->type);
3746:    _CAR(n) = mknode(F_COMMA_EXPR, CAR(n), mkintnode(0));    copy_pike_type(n->type, CDAR(n)->type);    } +  if (!Pike_compiler->compiler_frame || +  Pike_compiler->compiler_frame->current_return_type != +  void_type_string) { +  yywarning("Returning a void expression. Converted to zero.");    break;    } -  +  }    else if(Pike_compiler->compiler_frame &&    Pike_compiler->compiler_frame->current_return_type)    {
3771:    free_type( t );    t = pop_type();    Pike_compiler->compiler_frame->current_return_type = t; -  } else if ((Pike_compiler->compiler_frame->current_return_type != +  } else { +  node *retval = CAR(n); +  if (retval->token == F_COMMA_EXPR) { +  retval = CDR(retval); +  } +  if ((Pike_compiler->compiler_frame->current_return_type !=    void_type_string) || -  (CAR(n)->token != F_CONSTANT) || -  !SAFE_IS_ZERO(&CAR(n)->u.sval)) { +  (retval->token != F_CONSTANT) || +  !SAFE_IS_ZERO(&retval->u.sval)) {    check_node_type(CAR(n), t, "Wrong return type.");    }    } -  +  }    copy_pike_type(n->type, void_type_string);    break;