Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jNJJS-0001a3-Mj for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Apr 2020 16:48:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jNJJR-0008N0-Ij for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Apr 2020 16:48:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jNJJR-0008Mt-CE for pgsql-hackers@lists.postgresql.org; Sat, 11 Apr 2020 16:48:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jNJJP-0000cp-4w for pgsql-hackers@postgresql.org; Sat, 11 Apr 2020 16:48:56 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 03BGmouO019844; Sat, 11 Apr 2020 12:48:50 -0400 From: Tom Lane To: Andrew Dunstan cc: Noah Misch , PostgreSQL-development Subject: Re: cleaning perl code In-reply-to: <0a4406d5-b428-4831-8ed9-c36764360f57@2ndQuadrant.com> References: <20200411043014.GA590991@rfd.leadboat.com> <0a4406d5-b428-4831-8ed9-c36764360f57@2ndQuadrant.com> Comments: In-reply-to Andrew Dunstan message dated "Sat, 11 Apr 2020 12:13:08 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19842.1586623730.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 11 Apr 2020 12:48:50 -0400 Message-ID: <19843.1586623730@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andrew Dunstan writes: > On 4/11/20 12:30 AM, Noah Misch wrote: >> In summary, among those warnings, I see non-negative value in "Code bef= ore >> warnings are enabled" only. While we're changing this, I propose remov= ing >> Subroutines::RequireFinalReturn. Implicit return values were not a mat= erial >> source of PostgreSQL bugs, yet we've allowed this to litter our code: > That doesn't mean it won't be a source of problems in future, I've > actually been bitten by this in the past. Yeah, as I recall, the reason for the restriction is that if you fall out without a "return", what's returned is the side-effect value of the last statement, which might be fairly surprising. Adding explicit "return;" guarantees an undef result. So when this does prevent a bug it could be a pretty hard-to-diagnose one. The problem is that it's a really verbose/pedantic requirement for subs that no one ever examines the result value of. Is there a way to modify the test so that it only complains when the final return is missing and there are other return(s) with values? That would seem like a more narrowly tailored check. regards, tom lane