Re: clang's -Wmissing-variable-declarations shows some shoddy programming

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: clang's -Wmissing-variable-declarations shows some shoddy programming
Date: 2013-12-14 17:47:24
Message-ID: 20131214174724.GF3368@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2013-12-14 12:14:25 -0500, Tom Lane wrote:
> Andres Freund <andres(at)2ndquadrant(dot)com> writes:
> > Compiling postgres with said option in CFLAGS really gives an astounding
> > number of warnings. Except some bison/flex generated ones, none of them
> > looks acceptable to me.
>
> Given that we're not going to be able to get rid of the bison/flex cases,
> is this really something to bother with?

On a second look, it's not that hard to supress the warnings for
those. Something *roughly* like:

/*
* Declare variables defined by bison as extern, so clang doesn't complain
* about undeclared non-static variables.
*/
extern int plpgsql_yychar;
extern int plpgsql_yynerrs;

works.

> I agree I don't like cases where
> there's an "extern" in some other .c file rather than in a header, but I'm
> dubious about making a goal of suppressing this warning as such.

The cases where a 'static' is missing imo are cases that should clearly
be fixed, there's just no excuse for them. But it's an easy mistake to
make so having the compiler's support imo is helpful.

WRT the externs in .c files, if it were just old code, I wouldn't
bother. But we're regularly adding them. The last ones just last week in
316472146 and ef3267523 and several others aren't much older. So making
it a policy that can relatively easily be checked automatically not to
do so seems like a good idea.

Unfortunately gcc doesn't have a equivalent warning...

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Stark 2013-12-14 18:58:26 Re: stats for network traffic WIP
Previous Message Andres Freund 2013-12-14 17:37:17 Re: Changeset Extraction Interfaces