Re: Tree-walker callbacks vs -Wdeprecated-non-prototype
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2022-09-19T18:10:12Z
Lists: pgsql-hackers
Attachments
- clean-up-tree-walker-warnings-2.patch (text/x-diff) patch
Here's a second-generation patch that fixes the warnings by inserting
casts into a layer of macro wrappers. I had supposed that this would
cause us to lose all detection of wrongly-chosen walker functions,
so I was very pleased to see this when applying it to yesterday's HEAD:
execProcnode.c:792:2: warning: cast from 'bool (*)(PlanState *)' (aka 'bool (*)(struct PlanState *)') to 'planstate_tree_walker_callback' (aka 'bool (*)(struct PlanState *, void *)') converts to incompatible function type [-Wcast-function-type]
planstate_tree_walker(node, ExecShutdownNode, NULL);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../src/include/nodes/nodeFuncs.h:180:33: note: expanded from macro 'planstate_tree_walker'
planstate_tree_walker_impl(ps, (planstate_tree_walker_callback) (w), c)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So we've successfully suppressed the pedantic -Wdeprecated-non-prototype
warnings, and we have activated the actually-useful -Wcast-function-type
warnings, which seem to do exactly what we want in this context:
'-Wcast-function-type'
Warn when a function pointer is cast to an incompatible function
pointer. In a cast involving function types with a variable
argument list only the types of initial arguments that are provided
are considered. Any parameter of pointer-type matches any other
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pointer-type. Any benign differences in integral types are
^^^^^^^^^^^^
ignored, like 'int' vs. 'long' on ILP32 targets. Likewise type
qualifiers are ignored. The function type 'void (*) (void)' is
special and matches everything, which can be used to suppress this
warning. In a cast involving pointer to member types this warning
warns whenever the type cast is changing the pointer to member
type. This warning is enabled by '-Wextra'.
(That verbiage is from the gcc manual; clang seems to act the same
except that -Wcast-function-type is selected by -Wall, or perhaps is
even on by default.)
So I'm pretty pleased with this formulation: no caller changes are
needed, and it does exactly what we want warning-wise.
regards, tom lane
Commits
-
Remove accidentally added meson.build
- e7480f3dd6c2 13.22 landed
-
Disable clang 16's -Wcast-function-type-strict.
- 27831127d641 14.13 landed
- 6e2552d180a0 15.8 landed
- 101c37cd342a 16.0 landed
-
Disable -Wdeprecated-non-prototype in the back branches.
- 8c8ee5c99144 9.3 (unreleased) landed
- 5d3ce0d823c8 9.2 (unreleased) landed
- f9a56e726334 15.0 landed
- dcd7dbed5008 14.6 landed
- ca8fd341e165 9.6 (unreleased) landed
- 9afdf395042a 11.18 landed
- 7d5d3f05bfab 9.4 (unreleased) landed
- 52a5fd5b9f8f 12.13 landed
- 4c5a29c0e5e1 10.23 landed
- 43f72e0f73a5 13.9 landed
- 1b698659970e 9.5 (unreleased) landed
-
Revise tree-walk APIs to improve spec compliance & silence warnings.
- 1c27d16e6e5c 16.0 landed
-
Future-proof the recursion inside ExecShutdownNode().
- c35ba141de1f 16.0 landed
- cb7d636e0fb2 11.18 landed
- c58513f095e2 13.9 landed
- c403f97b4eab 15.0 landed
- adc26e0e88b3 12.13 landed
- 7394c763bc72 14.6 landed
- 68707e9c3f32 10.23 landed