Re: Unused header file inclusion - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Unused header file inclusion
Date
Msg-id 17463.1566153454@sss.pgh.pa.us
Whole thread Raw
In response to Re: Unused header file inclusion  (Andres Freund <andres@anarazel.de>)
Responses Re: Unused header file inclusion
Re: Unused header file inclusion
List pgsql-hackers
Andres Freund <andres@anarazel.de> writes:
> I've pushed the other ones.

Checking whether header files compile standalone shows you were overly
aggressive about removing fmgr.h includes:

In file included from /tmp/headerscheck.Ss8bVx/test.c:3:
./src/include/utils/selfuncs.h:143: error: expected declaration specifiers or '...' before 'FmgrInfo'
./src/include/utils/selfuncs.h:146: error: expected declaration specifiers or '...' before 'FmgrInfo'
./src/include/utils/selfuncs.h:152: error: expected declaration specifiers or '...' before 'FmgrInfo'

That's with a script I use that's like cpluspluscheck except it tests
with plain gcc not g++.  I attached it for the archives' sake.

Oddly, cpluspluscheck does not complain about those cases, but it
does complain about

In file included from /tmp/cpluspluscheck.FgX2SW/test.cpp:4:
./src/bin/scripts/scripts_parallel.h:18: error: ISO C++ forbids declaration of 'PGconn' with no type
./src/bin/scripts/scripts_parallel.h:18: error: expected ';' before '*' token
./src/bin/scripts/scripts_parallel.h:29: error: 'PGconn' has not been declared

(My headerscheck script is missing that header; I need to update it to
match the latest version of cpluspluscheck.)

            regards, tom lane

#!/bin/sh

# Check all exported PostgreSQL include files for standalone build.

# Run this from the top-level source directory after performing a build.
# No output if everything is OK, else compiler errors.

me=`basename $0`

tmp=`mktemp -d /tmp/$me.XXXXXX`

trap 'rm -rf $tmp' 0 1 2 3 15

# This should match what configure chooses, though we only care about -Wxxx
CFLAGS="-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute-Wformat-security -D_GNU_SOURCE -I . -I src/include -I src/interfaces/libpq $CFLAGS" 

# Omit src/include/port/, because it's platform specific, and c.h includes
# the relevant file anyway.
# rusagestub.h is also platform-specific, and will be included by
# utils/pg_rusage.h if necessary.
# access/rmgrlist.h is not meant to be included standalone.
# regex/regerrs.h is not meant to be included standalone.
# parser/gram.h will be included by parser/gramparse.h.
# parser/kwlist.h is not meant to be included standalone.
# pg_trace.h and utils/probes.h can include sys/sdt.h from SystemTap,
# which itself contains C++ code and so won't compile with a C++
# compiler under extern "C" linkage.

for f in `find src/include src/interfaces/libpq/libpq-fe.h src/interfaces/libpq/libpq-events.h -name '*.h' -print | \
    grep -v -e ^src/include/port/ \
    -e ^src/include/rusagestub.h -e ^src/include/regex/regerrs.h \
    -e ^src/include/access/rmgrlist.h \
    -e ^src/include/parser/gram.h -e ^src/include/parser/kwlist.h \
    -e ^src/include/pg_trace.h -e ^src/include/utils/probes.h`
do
    {
        test $f != "src/include/postgres_fe.h" && echo '#include "postgres.h"'
        echo "#include \"$f\""
    } >$tmp/test.c

    ${CC:-gcc} $CFLAGS -c $tmp/test.c -o $tmp/test.o
done

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [PATCH] minor doc fix for create-role
Next
From: Tom Lane
Date:
Subject: Re: Rethinking opclass member checks and dependency strength