From b133812ebe3bdcdb8ea46bf1fd5a865ad8e2e824 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 3 Nov 2026 15:39:36 +0100 Subject: [PATCH 03/10] Fix -Wcast-qual warning in foreach_delete_current() foreach_delete_current() returned the value of an assignment to the loop state's "const List *" field, and then cast away the const to return List *. The value comes from list_delete_nth_cell() and was never const, so restructure with a small inline helper that returns the List * directly, avoiding the cast altogether. Also, this way the pg_nodiscard attribute of list_delete_nth_cell() can be passed through. --- src/include/nodes/pg_list.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h index 2d16e0819ca..295626473d5 100644 --- a/src/include/nodes/pg_list.h +++ b/src/include/nodes/pg_list.h @@ -421,7 +421,7 @@ lnext(const List *l, const ListCell *c) * active foreach or foreach_* loop's list in any other way! */ #define foreach_delete_current(lst, var_or_cell) \ - ((List *) (var_or_cell##__state.l = list_delete_nth_cell(lst, var_or_cell##__state.i--))) + foreach_delete_current_impl(lst, &var_or_cell##__state) /* * foreach_current_index - @@ -715,4 +715,14 @@ extern void list_sort(List *list, list_sort_comparator cmp); extern int list_int_cmp(const ListCell *p1, const ListCell *p2); extern int list_oid_cmp(const ListCell *p1, const ListCell *p2); +/* support for foreach_delete_current() */ +pg_nodiscard static inline List * +foreach_delete_current_impl(List *lst, ForEachState *state) +{ + List *result = list_delete_nth_cell(lst, state->i--); + + state->l = result; + return result; +} + #endif /* PG_LIST_H */ -- 2.56.0