More const-marking cleanup
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Date: 2025-12-04T22:09:30Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix some cases of indirectly casting away const.
- de77775a7b50 18.4 landed
- cc9c22a5160a 15.18 landed
- a56a70141e09 17.10 landed
- 244c047205bb 14.23 landed
- 0969bfd0db86 16.14 landed
- 8f1791c61836 19 (unreleased) landed
-
Fix another case of indirectly casting away const.
- 9f7565c6c2d4 19 (unreleased) landed
-
ecpg: refactor to eliminate cast-away-const in find_variable().
- 4eda42e8bdf5 19 (unreleased) landed
Attachments
- v1-fix-missing-const-markers.patch (text/x-diff) patch v1
I noticed that our two buildfarm animals that are running Fedora
rawhide (caiman, midge) are emitting warnings like
compression.c: In function "parse_compress_options":
compression.c:458:13: warning: assignment discards "const" qualifier from pointer target type [-Wdiscarded-qualifiers]
458 | sep = strchr(option, ':');
| ^
Apparently, latest gcc is able to notice that constructions like
const char *str = ...;
char *ptr = strchr(str, ':');
are effectively casting away const. This is a good thing and long
overdue, but we have some work to do to clean up the places where
we are doing that.
Attached is a patch that cleans up all the cases I saw on a local
rawhide installation. Most of it is unremarkable, but the changes
in ecpg are less so. In particular, variable.c is a mess, because
somebody const-ified some of the char* arguments to find_struct()
and find_struct_member() without regard for the fact that all their
char* arguments point at the same string. (Not that you could
discover that from their nonexistent documentation.) I considered
just reverting that change, but was able to fix things up reasonably
well at the price of a few extra strdup's. It turned out that
find_struct_member()'s modification of its input string is actually
entirely useless, because it undoes that before consulting the
string again. find_struct() and find_variable() need to make
copies, though.
regards, tom lane