From patchwork Wed May 19 14:14:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 43497 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 4E385393A41F; Wed, 19 May 2021 14:14:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E385393A41F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1621433697; bh=nQkC65rSvn5qg4e4CbMM3E3ZQ6yCCxWiNVppz/HpfWk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=YmsWyUp40P5y4DtBWYEc1cb3dCMs1XW3I9t40cldZKQzDNDAM/u87pPI+4WoWjPZa VVLJ2GxqXc6P1bMOleD4usMy4a0LlMCd+kyJR0GLcozm811BDCI0lFq8zDtKS8gujk B+RLf2bLxa8NOYik1ObEP2TTO9XL7pWzBhh4n+cA= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id CC90E386FC25 for ; Wed, 19 May 2021 14:14:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CC90E386FC25 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-595-7omJKgAHNOiMcZo2B_59mA-1; Wed, 19 May 2021 10:14:52 -0400 X-MC-Unique: 7omJKgAHNOiMcZo2B_59mA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 583351926DB4 for ; Wed, 19 May 2021 14:14:51 +0000 (UTC) Received: from localhost (unknown [10.33.36.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 096F65D6AC for ; Wed, 19 May 2021 14:14:50 +0000 (UTC) Date: Wed, 19 May 2021 15:14:50 +0100 To: libc-alpha@sourceware.org Subject: [PATCH] Suppress -Wcast-qual warnings in bsearch Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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-Patchwork-Original-From: Jonathan Wakely via Libc-alpha From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" This fixes these GCC warnings when -Wsystem-headers is used: /usr/include/bits/stdlib-bsearch.h: In function ‘bsearch’: /usr/include/bits/stdlib-bsearch.h:32:13: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual] 32 | __p = (void *) (((const char *) __base) + (__idx * __size)); | ^ /usr/include/bits/stdlib-bsearch.h:39:16: warning: cast discards ‘const’ qualifier from pointer target type [-Wcast-qual] 39 | return (void *) __p; | ^ OK to push? commit 2e988862a07b75b433468cfd591a8acb1ab4f0af Author: Jonathan Wakely Date: Wed May 19 14:58:50 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. Reviewed-by: Florian Weimer diff --git a/bits/stdlib-bsearch.h b/bits/stdlib-bsearch.h index 4132dc6af0..a08ad34ed6 100644 --- a/bits/stdlib-bsearch.h +++ b/bits/stdlib-bsearch.h @@ -29,14 +29,17 @@ 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 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-qual" return (void *) __p; +#pragma GCC diagnostic pop } return NULL;