From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id F1A023857C56 for ; Thu, 30 Sep 2021 16:42:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F1A023857C56 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: EBcI3GskweQsWzOpLkmfQYWxgyyHCwOBDoJw9p0Gzr3tVtzsT1+SF/F98d92mV3fCFM4zQJwbG QG2i5ATH9wIXYhdHGYOvp5w8PlBKqZxX/hz8AsLVlBrFVbDFVO5tzsq6Av2oGAuuMWO001fn1Z 3ogLENPNlEsIdFhztrWtz4WY4VBdMNIhSQTMzAfiAi3/VS+qTlihkYBcCriPaBNgmOwqSsdZH4 trc7Bc8bvTlwslKgZpsRYrMc84br4Nm7fZb5chPoayUCQY2ZYJpUUG9gPfecSq+5GiZHJlQHOh EIJw6q9NiMo/axcxiaD7zRQF X-IronPort-AV: E=Sophos;i="5.85,336,1624348800"; d="scan'208";a="66506588" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 30 Sep 2021 08:42:10 -0800 IronPort-SDR: 1B9Du17Okj9GJdTUwBbpV1xK7KJxLA8P1HctSMyZAESasdSfB66g+nead1wnRD1HK2d+PFHhlC A0Gk5GRZQalCWPOHsnRCs0dxNU1RipWU4K3JQDVq63AykrlGIE4EH62IQe0PsJEqs80vaDg0jI uhaE7c1f0Owkwy8tN4u8NmXkcfeE9Sz3e5692qwElbblWL2bQH6XDV0vTbK2hcLUeCZNV7YTSu SgKqmkns+5pb0D9smSz7s0G1AxwnHYWIznG4zikDvAMKydJZHtCYTBRGOUayLuCzoIGQxwTW3j tgA= Date: Thu, 30 Sep 2021 16:42:04 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Adhemerval Zanella CC: Jonathan Wakely , Subject: Re: [PATCH v2] Suppress -Wcast-qual warnings in bsearch In-Reply-To: <71d5e560-e6c5-6167-f015-ca73d3e0fdff@linaro.org> Message-ID: References: <87czoq4a44.fsf@oldenburg.str.redhat.com> <069fcec4-d81f-3ea8-d87c-ff3b281dbe71@linaro.org> <71d5e560-e6c5-6167-f015-ca73d3e0fdff@linaro.org> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3118.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Sep 2021 16:42:13 -0000 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