Andres Freund <andres@anarazel.de> 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: ‘ereport’ undeclared (first use in this
function);did you mean ‘rresvport’?
> 3727 | ereport(FATAL,
> | ^~~~~~~
> | rresvport
> /home/andres/src/postgresql/src/backend/tcop/postgres.c:3727:4: note: each undeclared identifier is reported only
oncefor each function it appears 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