Skip to content

fix discarded-qualifiers warnings with GCC 16+#158

Open
graysky2 wants to merge 1 commit into
openwrt:masterfrom
graysky2:gcc16
Open

fix discarded-qualifiers warnings with GCC 16+#158
graysky2 wants to merge 1 commit into
openwrt:masterfrom
graysky2:gcc16

Conversation

@graysky2

Copy link
Copy Markdown

strpbrk() returns char * even when passed a const char *, a known C standard wart. Explicitly cast the return value to char * at all nine call sites to satisfy -Werror=discarded-qualifiers

strpbrk() returns char * even when passed a const char *, a known
C standard wart. Explicitly cast the return value to char * at all
nine call sites to satisfy -Werror=discarded-qualifiers

Signed-off-by: John Audia <therealgraysky@proton.me>
graysky2 added a commit to graysky2/openwrt that referenced this pull request May 26, 2026
Add pending openwrt/odhcp6c#158

This is needed for openwrt#23194

Signed-off-by: John Audia <therealgraysky@proton.me>
@bkuhls

bkuhls commented May 27, 2026

Copy link
Copy Markdown

Duplicate of #156?

@graysky2

graysky2 commented May 27, 2026

Copy link
Copy Markdown
Author

Claude thinks this PR is a better approach:

  • The POSIX signature of strpbrk is char *strpbrk(const char *s1, const char *s2) — it accepts a const char * input just fine, so casting the input in a.patch is unnecessary and misleading. It implies the function requires a mutable pointer, which it doesn't.
  • Casting the return value (PR#158) is the idiomatic C workaround for the classic const-correctness quirk where strpbrk loses the const qualifier on its return. It's the same pattern used in the C standard library wrappers for strchr, strstr, etc.
  • PR#156 casts on the input is effectively a no-op in terms of fixing the warning, and could confuse a future reader into thinking src's constness matters to strpbrk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants