More -Wshadow=compatible-local warning fixes
authorDavid Rowley <[email protected]>
Thu, 25 Aug 2022 14:35:40 +0000 (02:35 +1200)
committerDavid Rowley <[email protected]>
Thu, 25 Aug 2022 14:35:40 +0000 (02:35 +1200)
In a similar effort to f01592f91, here we're targetting fixing the
warnings where we've deemed the shadowing variable to serve a close enough
purpose to the shadowed variable just to reuse the shadowed version and
not declare the shadowing variable at all.

By my count, this takes the warning count from 106 down to 71.

Author: Justin Pryzby
Discussion: https://postgr.es/m/20220825020839[email protected]

20 files changed:
src/backend/access/hash/hash_xlog.c
src/backend/access/transam/multixact.c
src/backend/access/transam/xlog.c
src/backend/commands/functioncmds.c
src/backend/commands/tablecmds.c
src/backend/commands/vacuum.c
src/backend/executor/execPartition.c
src/backend/executor/nodeWindowAgg.c
src/backend/lib/integerset.c
src/backend/libpq/auth.c
src/backend/optimizer/path/indxpath.c
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/subselect.c
src/backend/optimizer/prep/prepunion.c
src/backend/postmaster/autovacuum.c
src/backend/rewrite/rowsecurity.c
src/backend/statistics/dependencies.c
src/backend/utils/adt/rangetypes_spgist.c
src/backend/utils/adt/ruleutils.c
src/bin/pgbench/pgbench.c

index 2e68303cbfdbe7c3161d85d8ca7c12bd9d12fcc3..e88213c74253a8533b462620375feebbcef00d03 100644 (file)
@@ -240,7 +240,6 @@ hash_xlog_add_ovfl_page(XLogReaderState *record)
                {
                        Page            mappage = (Page) BufferGetPage(mapbuffer);
                        uint32     *freep = NULL;
-                       char       *data;
                        uint32     *bitmap_page_bit;
 
                        freep = HashPageGetBitmap(mappage);
index 8f7d12950e59fdae3bd5eae0dd57eddfcd9d7d01..ec57f56adf3263fe5fbdb017fee2b80cebb7790f 100644 (file)
@@ -1614,7 +1614,6 @@ mXactCachePut(MultiXactId multi, int nmembers, MultiXactMember *members)
        if (MXactCacheMembers++ >= MAX_CACHE_ENTRIES)
        {
                dlist_node *node;
-               mXactCacheEnt *entry;
 
                node = dlist_tail_node(&MXactCache);
                dlist_delete(node);
index 87b243e0d4bb17c19829d4e208dfdd6a174df662..537845cada764acb19a068e029f72dc4c7eefaec 100644 (file)
@@ -3036,8 +3036,7 @@ XLogFileInitInternal(XLogSegNo logsegno, TimeLineID logtli,
        pgstat_report_wait_start(WAIT_EVENT_WAL_INIT_SYNC);
        if (pg_fsync(fd) != 0)
        {
-               int                     save_errno = errno;
-
+               save_errno = errno;
                close(fd);
                errno = save_errno;
                ereport(ERROR,
@@ -4721,7 +4720,6 @@ XLogInitNewTimeline(TimeLineID endTLI, XLogRecPtr endOfLog, TimeLineID newTLI)
 
                if (close(fd) != 0)
                {
-                       char            xlogfname[MAXFNAMELEN];
                        int                     save_errno = errno;
 
                        XLogFileName(xlogfname, newTLI, startLogSegNo, wal_segment_size);
index e7e37146f6922b0ee552b46a64b17c305e5ed49d..e6fcfc23b9316ca03b3b908b037bb8fdafc195cd 100644 (file)
@@ -121,7 +121,6 @@ compute_return_type(TypeName *returnType, Oid languageOid,
        {
                char       *typnam = TypeNameToString(returnType);
                Oid                     namespaceId;
-               AclResult       aclresult;
                char       *typname;
                ObjectAddress address;
 
@@ -1112,8 +1111,6 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
        if (languageStruct->lanpltrusted)
        {
                /* if trusted language, need USAGE privilege */
-               AclResult       aclresult;
-
                aclresult = pg_language_aclcheck(languageOid, GetUserId(), ACL_USAGE);
                if (aclresult != ACLCHECK_OK)
                        aclcheck_error(aclresult, OBJECT_LANGUAGE,
index 9be04c8a1e7386115c1ab725148d610f804590bc..dacc989d855ac2ccbd116beccb32db15b10ea6a4 100644 (file)
@@ -16796,7 +16796,6 @@ PreCommit_on_commit_actions(void)
        if (oids_to_drop != NIL)
        {
                ObjectAddresses *targetObjects = new_object_addresses();
-               ListCell   *l;
 
                foreach(l, oids_to_drop)
                {
index dbdfe8bd2d419070d3ba07b04dbec45f113f9297..3670d1f18610cbe81eed2a1770d78d8745ae42dc 100644 (file)
@@ -233,8 +233,6 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
         */
        if (!(params.options & VACOPT_ANALYZE))
        {
-               ListCell   *lc;
-
                foreach(lc, vacstmt->rels)
                {
                        VacuumRelation *vrel = lfirst_node(VacuumRelation, lc);
index ac03271882f17d3b7f5ab72e0efe3af00526c2ea..901dd435efdfaf3af36dc56873927b30925fdcb7 100644 (file)
@@ -768,7 +768,6 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, EState *estate,
                        {
                                List       *onconflset;
                                List       *onconflcols;
-                               bool            found_whole_row;
 
                                /*
                                 * Translate expressions in onConflictSet to account for
index 4b104c4d98a61a13bfd2e0bccabc3a6a6351fb7f..8b0858e9f5f0035a5da86afd4fcd70338faf89d4 100644 (file)
@@ -2062,12 +2062,13 @@ ExecWindowAgg(PlanState *pstate)
        if (winstate->all_first)
        {
                int                     frameOptions = winstate->frameOptions;
-               ExprContext *econtext = winstate->ss.ps.ps_ExprContext;
                Datum           value;
                bool            isnull;
                int16           len;
                bool            byval;
 
+               econtext = winstate->ss.ps.ps_ExprContext;
+
                if (frameOptions & FRAMEOPTION_START_OFFSET)
                {
                        Assert(winstate->startOffset != NULL);
index 5aff292c287ed775941f594c7197b6872987ba63..41d3abdb09cf8573b547318689fe62228364e46e 100644 (file)
@@ -565,8 +565,6 @@ intset_is_member(IntegerSet *intset, uint64 x)
         */
        if (intset->num_buffered_values > 0 && x >= intset->buffered_values[0])
        {
-               int                     itemno;
-
                itemno = intset_binsrch_uint64(x,
                                                                           intset->buffered_values,
                                                                           intset->num_buffered_values,
index 2e7330f7bc62a126b36ca53573cae1379b3984e8..10cd19e6cd9991d10fb0941f481e9bc286773cf3 100644 (file)
@@ -1652,8 +1652,6 @@ interpret_ident_response(const char *ident_response,
                                                return false;
                                        else
                                        {
-                                               int                     i;      /* Index into *ident_user */
-
                                                cursor++;       /* Go over colon */
                                                while (pg_isblank(*cursor))
                                                        cursor++;       /* skip blanks */
index 7d176e7b00aba5730945f3bfa23a111dcbe64613..045ff2e487ec9a830f5878c063fe03d3dbf3ade0 100644 (file)
@@ -361,7 +361,6 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
        if (bitjoinpaths != NIL)
        {
                List       *all_path_outers;
-               ListCell   *lc;
 
                /* Identify each distinct parameterization seen in bitjoinpaths */
                all_path_outers = NIL;
@@ -2188,7 +2187,7 @@ match_clause_to_index(PlannerInfo *root,
                /* Ignore duplicates */
                foreach(lc, clauseset->indexclauses[indexcol])
                {
-                       IndexClause *iclause = (IndexClause *) lfirst(lc);
+                       iclause = (IndexClause *) lfirst(lc);
 
                        if (iclause->rinfo == rinfo)
                                return;
index d929ce341716db2a6e21c66e68fd059566b5b603..079bd0bfdfdde32a87c70da49c6a98660bb009a7 100644 (file)
@@ -3484,8 +3484,6 @@ get_number_of_groups(PlannerInfo *root,
 
                        if (gd->hash_sets_idx)
                        {
-                               ListCell   *lc;
-
                                gd->dNumHashGroups = 0;
 
                                groupExprs = get_sortgrouplist_exprs(parse->groupClause,
@@ -4720,8 +4718,6 @@ create_final_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel,
        Path       *cheapest_input_path = input_rel->cheapest_total_path;
        double          numDistinctRows;
        bool            allow_hash;
-       Path       *path;
-       ListCell   *lc;
 
        /* Estimate number of distinct rows there will be */
        if (parse->groupClause || parse->groupingSets || parse->hasAggs ||
@@ -4766,6 +4762,8 @@ create_final_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel,
                 * the other.)
                 */
                List       *needed_pathkeys;
+               Path       *path;
+               ListCell   *lc;
 
                if (parse->hasDistinctOn &&
                        list_length(root->distinct_pathkeys) <
@@ -4776,7 +4774,7 @@ create_final_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel,
 
                foreach(lc, input_rel->pathlist)
                {
-                       Path       *path = (Path *) lfirst(lc);
+                       path = (Path *) lfirst(lc);
 
                        if (pathkeys_contained_in(needed_pathkeys, path->pathkeys))
                        {
@@ -5034,8 +5032,6 @@ create_ordered_paths(PlannerInfo *root,
                 */
                if (enable_incremental_sort && list_length(root->sort_pathkeys) > 1)
                {
-                       ListCell   *lc;
-
                        foreach(lc, input_rel->partial_pathlist)
                        {
                                Path       *input_path = (Path *) lfirst(lc);
@@ -7607,7 +7603,6 @@ apply_scanjoin_target_to_paths(PlannerInfo *root,
                        AppendRelInfo **appinfos;
                        int                     nappinfos;
                        List       *child_scanjoin_targets = NIL;
-                       ListCell   *lc;
 
                        Assert(child_rel != NULL);
 
index df4ca1291912b7aca7be1fc644fab50aef59cad7..92e33385842ce3d6749e4e79e7d771eeae56e20a 100644 (file)
@@ -2554,8 +2554,6 @@ finalize_plan(PlannerInfo *root, Plan *plan,
 
                case T_Append:
                        {
-                               ListCell   *l;
-
                                foreach(l, ((Append *) plan)->appendplans)
                                {
                                        context.paramids =
@@ -2571,8 +2569,6 @@ finalize_plan(PlannerInfo *root, Plan *plan,
 
                case T_MergeAppend:
                        {
-                               ListCell   *l;
-
                                foreach(l, ((MergeAppend *) plan)->mergeplans)
                                {
                                        context.paramids =
@@ -2588,8 +2584,6 @@ finalize_plan(PlannerInfo *root, Plan *plan,
 
                case T_BitmapAnd:
                        {
-                               ListCell   *l;
-
                                foreach(l, ((BitmapAnd *) plan)->bitmapplans)
                                {
                                        context.paramids =
@@ -2605,8 +2599,6 @@ finalize_plan(PlannerInfo *root, Plan *plan,
 
                case T_BitmapOr:
                        {
-                               ListCell   *l;
-
                                foreach(l, ((BitmapOr *) plan)->bitmapplans)
                                {
                                        context.paramids =
@@ -2622,8 +2614,6 @@ finalize_plan(PlannerInfo *root, Plan *plan,
 
                case T_NestLoop:
                        {
-                               ListCell   *l;
-
                                finalize_primnode((Node *) ((Join *) plan)->joinqual,
                                                                  &context);
                                /* collect set of params that will be passed to right child */
index 043181b586bccc51f785798033e17d30134eecb2..71052c841d756cabd464c0ce80b32018b7108d1b 100644 (file)
@@ -653,7 +653,6 @@ generate_union_paths(SetOperationStmt *op, PlannerInfo *root,
        if (partial_paths_valid)
        {
                Path       *ppath;
-               ListCell   *lc;
                int                     parallel_workers = 0;
 
                /* Find the highest number of workers requested for any subpath. */
index 70a9176c54ca944d0454f0b3d21df169271f75c4..b3b1afba86183c02f5915f03547fba1d910f4a96 100644 (file)
@@ -1102,7 +1102,7 @@ rebuild_database_list(Oid newdb)
                 */
                for (i = 0; i < nelems; i++)
                {
-                       avl_dbase  *db = &(dbary[i]);
+                       db = &(dbary[i]);
 
                        current_time = TimestampTzPlusMilliseconds(current_time,
                                                                                                           millis_increment);
index a233dd475857a839879d90030d0d0d0d02aa8560..b2a723743068b8aaefac201b8e447a14f77c8031 100644 (file)
@@ -824,7 +824,6 @@ add_with_check_options(Relation rel,
                {
                        RowSecurityPolicy *policy = (RowSecurityPolicy *) lfirst(item);
                        Expr       *qual = QUAL_FOR_WCO(policy);
-                       WithCheckOption *wco;
 
                        if (qual != NULL)
                        {
index c1c27e67d474f5feb01b8cc98f74c8a2c8e19251..bf698c1fc3f0e8e332e78631ec3f8f7bce84da65 100644 (file)
@@ -1265,7 +1265,6 @@ dependency_is_compatible_expression(Node *clause, Index relid, List *statlist, N
        else if (is_orclause(clause))
        {
                BoolExpr   *bool_expr = (BoolExpr *) clause;
-               ListCell   *lc;
 
                /* start with no expression (we'll use the first match) */
                *expr = NULL;
index 1190b8000bcc7519c8d51c5580b94c440ae75e3e..71a6053b6a0baeb01cc1f887fb4e3f42dfcb662d 100644 (file)
@@ -693,7 +693,6 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
                                 * quadrants if we're looking for a value strictly greater
                                 * than the maximum.
                                 */
-                               int                     cmp;
 
                                cmp = range_cmp_bounds(typcache, &centroidLower, maxLower);
                                if (cmp > 0 || (!inclusive && cmp == 0))
@@ -721,7 +720,6 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
                                 * quadrants if we're looking for a value strictly greater
                                 * than the maximum.
                                 */
-                               int                     cmp;
 
                                cmp = range_cmp_bounds(typcache, &centroidUpper, maxUpper);
                                if (cmp > 0 || (!inclusive && cmp == 0))
index 8280711f7ef02070abcffec8fd6e9961929f1edb..9959f6910e9c5b83c46940c4732b7d26bebf8dac 100644 (file)
@@ -1303,7 +1303,6 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
        if (!heap_attisnull(ht_idx, Anum_pg_index_indexprs, NULL))
        {
                Datum           exprsDatum;
-               bool            isnull;
                char       *exprsString;
 
                exprsDatum = SysCacheGetAttr(INDEXRELID, ht_idx,
@@ -1500,7 +1499,6 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
                {
                        Node       *node;
                        Datum           predDatum;
-                       bool            isnull;
                        char       *predString;
 
                        /* Convert text string to node tree */
@@ -1945,7 +1943,6 @@ pg_get_partkeydef_worker(Oid relid, int prettyFlags,
        if (!heap_attisnull(tuple, Anum_pg_partitioned_table_partexprs, NULL))
        {
                Datum           exprsDatum;
-               bool            isnull;
                char       *exprsString;
 
                exprsDatum = SysCacheGetAttr(PARTRELID, tuple,
index c0e907d437379ba7c3bf8c62234a5e339b2704bc..07b7e0cf37c687417111c8877ef3b5e3c4918f03 100644 (file)
@@ -3109,7 +3109,6 @@ sendCommand(CState *st, Command *command)
                        for (j = 0; commands[j] != NULL; j++)
                        {
                                PGresult   *res;
-                               char            name[MAX_PREPARE_NAME];
 
                                if (commands[j]->type != SQL_COMMAND)
                                        continue;
@@ -3803,8 +3802,6 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
                                /* quickly skip commands until something to do... */
                                while (true)
                                {
-                                       Command    *command;
-
                                        command = sql_script[st->use_file].commands[st->command];
 
                                        /* cannot reach end of script in that state */
@@ -3959,8 +3956,6 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
                                 */
                                if (report_per_command)
                                {
-                                       Command    *command;
-
                                        pg_time_now_lazy(&now);
 
                                        command = sql_script[st->use_file].commands[st->command];