From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id BF3C03858D33 for ; Wed, 19 Apr 2023 16:23:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF3C03858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [10.0.0.170] (unknown [167.248.160.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 6F6541E0D3; Wed, 19 Apr 2023 12:23:19 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1681921399; bh=2eRGjYgJpl9Tgq2E+TDxZ4Cn8oejrpD5dZZDoEZIM2Y=; h=Date:Subject:To:References:From:In-Reply-To:From; b=tbckOwCFc63XQfefMl3nX5763Wzdl34owL0vi9kdcqLqW5XZnLgyiwXuQC7egGUnI 3q9fUfAta2wH05Djfz+Qi02KBIzKzo3as0xa5OliiBi1PtIIINW7XWE7ZHidlGdB9x 7N2+MHCOkHO/BsVPlxWJAtYKH5tW+ZCIBAE0vBXY= Message-ID: <119e1750-83c2-9e9f-a60a-3c14b2d6c09a@simark.ca> Date: Wed, 19 Apr 2023 12:23:18 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] Rewrite gdb_mpz::operator== Content-Language: fr To: Tom Tromey , gdb-patches@sourceware.org References: <20230419150931.2047832-1-tromey@adacore.com> From: Simon Marchi In-Reply-To: <20230419150931.2047832-1-tromey@adacore.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 4/19/23 11:09, Tom Tromey via Gdb-patches wrote: > Simon pointed out that the recent changes to gdb_mpz caused a build > failure on macOS. It turns out to be somewhat difficult to overload a For some reason, just macOS on amd64, not arm64. > method in a way that will work "naturally" for all integer types; > especially in a case like gdb_mpz::operator==, where it's desirable to > special case all integer types that are no wider than 'long'. > > After a false start, I came up with this patch, which seems to work. > It applies the desirable GMP special cases directly in the body, > rather than via overloads. > --- > gdb/gmp-utils.h | 38 ++++++++++++++------------------------ > 1 file changed, 14 insertions(+), 24 deletions(-) > > diff --git a/gdb/gmp-utils.h b/gdb/gmp-utils.h > index d05c11ecbe4..3586d01b0f9 100644 > --- a/gdb/gmp-utils.h > +++ b/gdb/gmp-utils.h > @@ -323,31 +323,21 @@ struct gdb_mpz > return mpz_cmp_si (m_val, other) < 0; > } > > - bool operator== (int other) const > - { > - return mpz_cmp_si (m_val, other) == 0; > - } > - > - bool operator== (long other) const > - { > - return mpz_cmp_si (m_val, other) == 0; > - } > - > - bool operator== (unsigned long other) const > - { > - return mpz_cmp_ui (m_val, other) == 0; > - } > - > template - typename = gdb::Requires< > - gdb::And, > - std::integral_constant - (sizeof (T) > sizeof (long))>> > - > > - > > - bool operator== (T src) > - { > - return *this == gdb_mpz (src); > + typename = gdb::Requires>> > + bool operator== (T other) const > + { > + if (std::is_signed::value) > + { > + if (other == (T) (long) other) It's a bit hard to understand what the intent is, if you don't know the problematic already. Could you add a comment explaining that? Also, wouldn't it work to compare size? Like: if (sizeof (T) <= sizeof (long)) Simon