[PATCH v2] Suppress -Wcast-qual warnings in bsearch
Joseph Myers
joseph@codesourcery.com
Thu Sep 30 16:42:04 GMT 2021
On Thu, 30 Sep 2021, Adhemerval Zanella via Libc-alpha wrote:
> On 30/09/2021 12:07, Joseph Myers wrote:
> > On Thu, 30 Sep 2021, Adhemerval Zanella via Libc-alpha wrote:
> >
> >>>> else
> >>>> +#if __GNUC_PREREQ(4, 6)
> >>>> +# pragma GCC diagnostic push
> >>>> +# pragma GCC diagnostic ignored "-Wcast-qual"
> >>>> +#endif
> >>>> return (void *) __p;
> >>>> +#if __GNUC_PREREQ(4, 6)
> >>>> +# pragma GCC diagnostic pop
> >>>> +#endif
> >>>> }
> >
> > I think braces may need adding around those pragmas to avoid a pragma
> > being considered the body of the else in some cases.
>
> But how exactly the pragma is changing the code semantic in this case?
The effect, when the #pragma is treated as a statement by the C parser, is
that the prior cases of the "if" fall through to the "return", which
becomes unconditional, when otherwise they would not have returned.
> Would it be safe for all supported gcc (since it is an installed header)?
The #if conditionals are still needed. It's just that braces should be
added before the first #if and after the last #endif, to avoid a single
#pragma being considered as the else body (see GCC bug 41517 and other
bugs related to #pragma parsing).
--
Joseph S. Myers
joseph@codesourcery.com
More information about the Libc-alpha
mailing list