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 ESMTPS id 000D5385AC1B for ; Fri, 23 Sep 2022 16:16:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 000D5385AC1B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663949780; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vAvNgwJwP6n4+3GlYDQHqhUg0k60NMruBAi01I7cttI=; b=bq0k/t9es6CFOpsIpVlayl5Gs8yoAHT+HWX3isJTcKAGiGk5RW/VThmEhpZMnGSFK4jskl mIU1BNBApAyK3+Rip4j4Oct0sxE1Igv53AV23RrdC7VeH92lFxYJWZs0yBJqIW+YuDuVFe TTlhFrf6t5Gf50EyPlMytKbaZ+j6174= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-388-DPEBIfGLM1OM2uRZhuxcvw-1; Fri, 23 Sep 2022 12:16:19 -0400 X-MC-Unique: DPEBIfGLM1OM2uRZhuxcvw-1 Received: by mail-qv1-f71.google.com with SMTP id mx9-20020a0562142e0900b004a1ddfe8ee3so199419qvb.2 for ; Fri, 23 Sep 2022 09:16:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date; bh=vAvNgwJwP6n4+3GlYDQHqhUg0k60NMruBAi01I7cttI=; b=1faWtl7btUrdzA3cbcLYaQYTXfEfOdFqpb2gXc5PBsvVsLyrKnkb5BfPeT3W7G4Sdv g9wUWb3LrW2ErO1vVpWdaJYP26JCf0UwihHfA37AjehWgjMwtmtQMK5shdZL0HGHffMD AUkCsaB+xhhv1mZj32mt8L5HhZmFXlKZsuv+r4wCrJjziDy9kwFr1e12uu7xEViN2/B1 b5RzelknhoEntrOR8VSitJS4DNaOkKVzO/H3MiaZR95nfrXHhdYKi14ZuavzUuYmmuSm 6O19cic/R1RE4sGu5hue9l4O/recXzRBcLot3mgT9y8gfs1A78KGHDZqY3CgpqFenOMG pLQg== X-Gm-Message-State: ACrzQf1cLSKvk8ka0Y9wov1gM1Mh7zZQ4ISxhiLM+45Jl4T0LyCMttUc VVoUEvr6EuDqVCjlKxcbjIV/mrw0+J0lwj0dp93vGgmmK+0Q3qn31wUIrZ3Fe1clkfJe6V+/hIF Z89ZR2bvBs8My+MQ= X-Received: by 2002:a05:6214:1cc9:b0:496:aa2c:c927 with SMTP id g9-20020a0562141cc900b00496aa2cc927mr7471928qvd.15.1663949778733; Fri, 23 Sep 2022 09:16:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Bte5iqKn17WcWpf5NPAisBVJg9QPRN/UlAekeQvfUjtli1NKy8ZB9WN1eXn1o0mUcRPtUAw== X-Received: by 2002:a05:6214:1cc9:b0:496:aa2c:c927 with SMTP id g9-20020a0562141cc900b00496aa2cc927mr7471905qvd.15.1663949778433; Fri, 23 Sep 2022 09:16:18 -0700 (PDT) Received: from redhat.com (2603-7000-9500-2e39-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:2e39::1db4]) by smtp.gmail.com with ESMTPSA id c2-20020a05620a268200b006bb49cfe147sm6287308qkp.84.2022.09.23.09.16.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 09:16:17 -0700 (PDT) Date: Fri, 23 Sep 2022 12:16:15 -0400 From: Marek Polacek To: Jason Merrill Cc: GCC Patches , libstdc++ , Jonathan Wakely Subject: Re: [PATCH] c++: Implement __is_{nothrow_,}convertible [PR106784] Message-ID: References: <20220922133900.142238-1-polacek@redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.7 (2022-08-07) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,TXREP 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 Fri, Sep 23, 2022 at 11:54:53AM -0400, Jason Merrill wrote: > On 9/23/22 10:34, Marek Polacek wrote: > > On Thu, Sep 22, 2022 at 06:14:44PM -0400, Jason Merrill wrote: > > > On 9/22/22 09:39, Marek Polacek wrote: > > > > To improve compile times, the C++ library could use compiler built-ins > > > > rather than implementing std::is_convertible (and _nothrow) as class > > > > templates. This patch adds the built-ins. We already have > > > > __is_constructible and __is_assignable, and the nothrow forms of those. > > > > > > > > Microsoft (and clang, for compatibility) also provide an alias called > > > > __is_convertible_to. I did not add it, but it would be trivial to do > > > > so. > > > > > > > > I noticed that our __is_assignable doesn't implement the "Access checks > > > > are performed as if from a context unrelated to either type" requirement, > > > > therefore std::is_assignable / __is_assignable give two different results > > > > here: > > > > > > > > class S { > > > > operator int(); > > > > friend void g(); // #1 > > > > }; > > > > > > > > void > > > > g () > > > > { > > > > // #1 doesn't matter > > > > static_assert(std::is_assignable::value, ""); > > > > static_assert(__is_assignable(int&, S), ""); > > > > } > > > > > > > > This is not a problem if __is_assignable is not meant to be used by > > > > the users. > > > > > > That's fine, it's not. > > Okay then. libstdc++ needs to make sure then that it's handled right. > > > > > > This patch doesn't make libstdc++ use the new built-ins, but I had to > > > > rename a class otherwise its name would clash with the new built-in. > > > > > > Sigh, that's going to be a hassle when comparing compiler versions on > > > preprocessed code. > > > > Yeah, I guess :/. Kind of like __integer_pack / __make_integer_seq. > > > > > > --- a/gcc/cp/constraint.cc > > > > +++ b/gcc/cp/constraint.cc > > > > @@ -3697,6 +3697,12 @@ diagnose_trait_expr (tree expr, tree args) > > > > case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: > > > > inform (loc, " %qT does not have unique object representations", t1); > > > > break; > > > > + case CPTK_IS_CONVERTIBLE: > > > > + inform (loc, " %qT is not convertible from %qE", t2, t1); > > > > + break; > > > > + case CPTK_IS_NOTHROW_CONVERTIBLE: > > > > + inform (loc, " %qT is not % convertible from %qE", t2, t1); > > > > > > It's odd that the existing diagnostics quote "nothrow", which is not a > > > keyword. I wonder why these library traits didn't use "noexcept"? > > > > Eh, yeah, only "throw" is. The quotes were deliberately added in > > . Should > > I prepare a separate patch to use "%" rather than "%"? > > OTOH, the traits have "nothrow" in their names, so maybe just go back to > > "nothrow"? > > The latter, I think. Or possibly "no-throw". I guess -Wformat-diag wants > "nothrow" quoted because of the attribute of that name. OK, let me see. > > > > --- a/gcc/cp/method.cc > > > > +++ b/gcc/cp/method.cc > > > > @@ -2236,6 +2236,37 @@ ref_xes_from_temporary (tree to, tree from, bool direct_init_p) > > > > return ref_conv_binds_directly (to, val, direct_init_p).is_false (); > > > > } > > > > +/* Return true if FROM can be converted to TO using implicit conversions, > > > > + or both FROM and TO are possibly cv-qualified void. NB: This doesn't > > > > + implement the "Access checks are performed as if from a context unrelated > > > > + to either type" restriction. */ > > > > + > > > > +bool > > > > +is_convertible (tree from, tree to) > > > > > > You didn't want to add conversion to is*_xible? > > > > No, it didn't look like a good fit. It does things we don't need, and > > also has if VOID_TYPE_P -> return error_mark_node; which would be wrong > > for __is_convertible. > > > > I realized I'm not testing passing an incomplete type to the built-in, > > but since that is UB, I reckon we don't need to test it (we issue > > "error: invalid use of incomplete type"). > > But your patch does test that, in the existing call to check_trait_type from > finish_trait_expr? Yes, it eventually checks complete_type_or_else. > The patch is OK. Thanks, Marek