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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 9343A3858024 for ; Tue, 1 Jun 2021 10:10:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9343A3858024 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-282-SP5030LVMTOWQeJVgG9IhA-1; Tue, 01 Jun 2021 06:10:03 -0400 X-MC-Unique: SP5030LVMTOWQeJVgG9IhA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 84AB56D241; Tue, 1 Jun 2021 10:10:02 +0000 (UTC) Received: from localhost (unknown [10.33.37.1]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1280A10013D6; Tue, 1 Jun 2021 10:09:58 +0000 (UTC) Date: Tue, 1 Jun 2021 11:09:58 +0100 From: Jonathan Wakely To: libc-alpha@sourceware.org Cc: Joseph Myers , carlos@redhat.com, dj@redhat.com Subject: [PATCH v3] 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.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="SCee+paMyJ4PKmMA" Content-Disposition: inline X-Spam-Status: No, score=-14.0 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: Tue, 01 Jun 2021 10:10:06 -0000 --SCee+paMyJ4PKmMA Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On 19/05/21 16:50 +0100, Jonathan Wakely wrote: >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. Resending patch v2 with a modified subject, to see if patchwork picks it up. --SCee+paMyJ4PKmMA 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; --SCee+paMyJ4PKmMA--