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 6105D3858D1E for ; Tue, 25 Apr 2023 18:55:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6105D3858D1E 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 8BBFE1E0D3; Tue, 25 Apr 2023 14:55:14 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1682448914; bh=vtVoyy7p5Tur8ksNoaOPC6Hvb0IZ+9fThLs7gHom9cU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ZJNIXdiB6yIxpYTZfx9gjjlir1G11MG2S0PMLgYf6nLFJISx65Xm9POZCxvJPdEnk TXXpZL4ndoDTnfMrf9ZLQ6pLHQ1IFDM1ylLrtK8Uqih0xKxFk5ogTsb2pyOtci37v2 G9+vtFbsN5TGexe++PTKgsxx9ybjmXaLsXRa9htI= Message-ID: Date: Tue, 25 Apr 2023 14:55:13 -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== To: Tom Tromey Cc: gdb-patches@sourceware.org References: <20230419150931.2047832-1-tromey@adacore.com> <119e1750-83c2-9e9f-a60a-3c14b2d6c09a@simark.ca> <875y9p2xvg.fsf@tromey.com> <87ttx9z3be.fsf@tromey.com> <87edo9z1fv.fsf@tromey.com> Content-Language: fr From: Simon Marchi In-Reply-To: <87edo9z1fv.fsf@tromey.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.4 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: > diff --git a/gdb/gmp-utils.h b/gdb/gmp-utils.h > index d05c11ecbe4..1bbdd9564fa 100644 > --- a/gdb/gmp-utils.h > +++ b/gdb/gmp-utils.h > @@ -323,31 +323,26 @@ 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; > - } > - > + /* We want an operator== that can handle all integer types. For > + types that are 'long' or narrower, we can use a GMP function and > + avoid boxing the RHS. But, because overloading based on integer > + type is a pain in C++, we accept all such types here and check > + the size in the body. */ > 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>> The template expression would fit on a single line, if you'd prefer to write it that way. Otherwise, LGTM. I think it's now relatively clear what the code tries to achieve. Approved-By: Simon Marchi Simon