Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jF4ev-0007Qr-1U for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Mar 2020 23:33:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jF4et-0004CO-Eq for pgsql-hackers@arkaria.postgresql.org; Thu, 19 Mar 2020 23:33:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jF4et-0004Bz-2u for pgsql-hackers@lists.postgresql.org; Thu, 19 Mar 2020 23:33:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jF4eq-0001Ts-OH for pgsql-hackers@lists.postgresql.org; Thu, 19 Mar 2020 23:33:01 +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 02JNWtTc005996; Thu, 19 Mar 2020 19:32:55 -0400 From: Tom Lane To: Andres Freund cc: Amit Kapila , Michael Paquier , Julien Rouhaud , Masahiko Sawada , PostgreSQL Hackers Subject: Re: Missing errcode() in ereport In-reply-to: <20200319230446.lxjybufdcgwaqkhj@alap3.anarazel.de> References: <20200317095839.GG2206@paquier.xyz> <32174.1584454158@sss.pgh.pa.us> <20200319175902.vjib2tslosw65iyr@alap3.anarazel.de> <5063.1584641224@sss.pgh.pa.us> <20200319230446.lxjybufdcgwaqkhj@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Thu, 19 Mar 2020 16:04:46 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <5994.1584660775.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 19 Mar 2020 19:32:55 -0400 Message-ID: <5995.1584660775@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andres Freund writes: > On 2020-03-19 14:07:04 -0400, Tom Lane wrote: >> Now that we can rely on having varargs macros, I think we could >> stop requiring the extra level of parentheses, > I think that'd be an improvement, because: > ane of the ones I saw confuse people is just: > /home/andres/src/postgresql/src/backend/tcop/postgres.c:3727:4: error: =E2= =80=98ereport=E2=80=99 undeclared (first use in this function); did you me= an =E2=80=98rresvport=E2=80=99? > 3727 | ereport(FATAL, > | ^~~~~~~ > | rresvport > /home/andres/src/postgresql/src/backend/tcop/postgres.c:3727:4: note: ea= ch undeclared identifier is reported only once for each function it appear= s in > because the extra parens haven't been added. Ah, so the macro isn't expanded at all if it appears to have more than two parameters? That seems odd, but I suppose some compilers might work that way. Switching to varargs would improve that for sure. > Another one I've both seen and committed byself is converting an elog to > an ereport, and not adding an errcode() around the error code - which > silently looks like it works. You mean not adding errmsg() around the error string? Yeah, I can believe that one easily. It's sort of the same problem as forgetting to wrap errcode() around the ERRCODE_ constant. I think that at least some compilers will complain about side-effect-free subexpressions of a comma expression. Could we restructure things so that the errcode/errmsg/etc calls form a standalone comma expression rather than appearing to be arguments of a varargs function? The compiler's got no hope of realizing there's anything wrong when it thinks it's passing an integer or string constant to a function it knows nothing about. But if it could see that nothing at all is being done with the constant, maybe we'd get somewhere. regards, tom lane