From: Phillip Wood Date: Wed, 01 Apr 2026 13:17:20 GMT Subject: Re: [PATCH 08/12] skip_prefix(): check const match between in and out params Message-ID: <14a417c6-fc80-4a7e-993d-57fff10896f8@gmail.com> In-Reply-To: <20260331235017.GH2328529@coredump.intra.peff.net> Hi peff On 01/04/2026 00:50, Jeff King wrote: > > +/* > + * Check that an out-parameter that is "at least as const as" a matching > + * in-parameter. For example, skip_prefix() will return "out" that is a subset > + * of "str". So: > + * > + * const str, const out: ok > + * non-const str, const out: ok > + * non-const str, non-const out: ok > + * const str, non-const out: compile error > + * > + * See the skip_prefix macro below for an example of use. > + */ > +#define CONST_OUTPARAM(in, out) \ > + ((const char **)(0 ? ((*(out) = (in)),(out)) : (out))) > +#define skip_prefix(str, prefix, out) \ > + skip_prefix((str), (prefix), CONST_OUTPARAM((str), (out))) This is clever but it changes the behavior of skip_prefix() which is documented as not touching out if it returns false. That may not matter in practice but there are nearly 600 callers so auditing them all would be quite an undertaking. Elsewhere there was some discussion about using type generic macros to fix the warnings. That would be more complex as we need to check if they were supported by the compiler but it would avoid changing the behavior. Thanks for working on fixing these warnings, your approach of trying to fix the underlying problem rather than casting away the warning is very welcome. Phillip