From patchwork Tue Jun 1 10:09:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 43646 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B1BE3844015; Tue, 1 Jun 2021 10:10:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B1BE3844015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1622542208; bh=NG09lLb7LQ42BJiRbXIHzuANQ30OscOBgNbM3TbPwR4=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=lCDrXfsPSplmqfaWeygrGef8LOr4M/nfBytDQJRtNO5k6Lm75Esa9iiFLBRb//7sO NZZiT9DzqiI2mDGGm2Gbh5mS2gBzaZ3qpBM6aOB5bzwsDvx8sjDN21xB1b9pVQmH/+ eADsqBZ4tUU/5G7fYIz34jN1AgeuNPsTQ6LIEnf8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 To: libc-alpha@sourceware.org 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-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-Patchwork-Original-From: Jonathan Wakely via Libc-alpha From: Jonathan Wakely Reply-To: Jonathan Wakely Cc: Joseph Myers Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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. 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;