From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 5FFB4393BC02 for ; Wed, 19 May 2021 15:50:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5FFB4393BC02 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-189-nBO6hJ0rMOucnjwiDWNiUw-1; Wed, 19 May 2021 11:50:40 -0400 X-MC-Unique: nBO6hJ0rMOucnjwiDWNiUw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F1E04803621; Wed, 19 May 2021 15:50:38 +0000 (UTC) Received: from localhost (unknown [10.33.36.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0DD11F4; Wed, 19 May 2021 15:50:38 +0000 (UTC) Date: Wed, 19 May 2021 16:50:37 +0100 From: Jonathan Wakely To: Joseph Myers Cc: libc-alpha@sourceware.org Subject: Re: [PATCH] Suppress -Wcast-qual warnings in bsearch Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="afeWKG33fqf5MHyt" Content-Disposition: inline X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Wed, 19 May 2021 15:50:44 -0000 --afeWKG33fqf5MHyt Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On 19/05/21 15:37 +0000, Joseph Myers wrote: >On Wed, 19 May 2021, Jonathan Wakely via Libc-alpha wrote: > >> +#pragma GCC diagnostic push >> +#pragma GCC diagnostic ignored "-Wcast-qual" >> return (void *) __p; >> +#pragma GCC diagnostic pop > >I think such pragma uses in installed headers should be conditional on >__GNUC_PREREQ (4, 6) (either directly or via conditionally defining a >macro in sys/cdefs.h). Good point. I spent about two minutes trying to do something with _Pragma in sys/cdefs.h to allow: __GLIBC_IGNORE_WARNING("-Wcast-qual") return (void *) __p; __GLIBC_UNIGNORE_WARNING but didn't get it working, so here's a patch that just tests __GNUC_PREREQ directly. --afeWKG33fqf5MHyt Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="bsearch.patch" commit ee7c2451a102b4cd3c87a31b3156ad4458729840 Author: Jonathan Wakely Date: Wed May 19 16:48:19 2021 +0100 Suppress -Wcast-qual warnings in bsearch The first cast to (void *) is redundant but should be (const void *) anyway, because that's the type of the lvalue being assigned to. The second cast is necessary and intentionally not const-correct, so tell the compiler not to warn about it. diff --git a/bits/stdlib-bsearch.h b/bits/stdlib-bsearch.h index 4132dc6af0..d688ed2e15 100644 --- a/bits/stdlib-bsearch.h +++ b/bits/stdlib-bsearch.h @@ -29,14 +29,21 @@ bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, while (__l < __u) { __idx = (__l + __u) / 2; - __p = (void *) (((const char *) __base) + (__idx * __size)); + __p = (const void *) (((const char *) __base) + (__idx * __size)); __comparison = (*__compar) (__key, __p); if (__comparison < 0) __u = __idx; else if (__comparison > 0) __l = __idx + 1; 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 } return NULL; --afeWKG33fqf5MHyt--