diff --git a/src/V3LinkJump.cpp b/src/V3LinkJump.cpp index 6e1b6f319..ae38c8fd5 100644 --- a/src/V3LinkJump.cpp +++ b/src/V3LinkJump.cpp @@ -234,7 +234,7 @@ private: return; } else if (!m_ftaskp) { nodep->v3error("Return isn't underneath a task or function"); - } else if (funcp && !nodep->lhsp()) { + } else if (funcp && !nodep->lhsp() && !funcp->isConstructor()) { nodep->v3error("Return underneath a function should have return value"); } else if (!funcp && nodep->lhsp()) { nodep->v3error("Return underneath a task shouldn't have return value"); diff --git a/test_regress/t/t_class_new_return.pl b/test_regress/t/t_class_new_return.pl new file mode 100755 index 000000000..bf4e4ce9f --- /dev/null +++ b/test_regress/t/t_class_new_return.pl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2022 by Antmicro Ltd. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(simulator => 1); + +compile(); + +execute( + check_finished => 1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_class_new_return.v b/test_regress/t/t_class_new_return.v new file mode 100644 index 000000000..2ee65b978 --- /dev/null +++ b/test_regress/t/t_class_new_return.v @@ -0,0 +1,36 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2022 by Antmicro Ltd. +// SPDX-License-Identifier: CC0-1.0 + +module t (/*AUTOARG*/ + clk + ); + + input clk; + + class foo; + int a; + function new; + a = 1; + return; + a = 2; + endfunction + function int get_a; + return a; + endfunction + endclass + + foo foo_i; + initial foo_i = new; + + always @(posedge clk) begin + if (foo_i.get_a() == 1) begin + $write("*-* All Finished *-*\n"); + $finish; + end + else + $stop; + end +endmodule