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 E1185385700F for ; Fri, 23 Sep 2022 14:34:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E1185385700F 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=1663943656; 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=VcaCTXc0xTM/SOMVKl51uT+JebyIeyyruekAC+urGX0=; b=f6y2nstpwKThGfwCc7cIOkpy1vYDLjZxHivenpGRBPk2NmrEuIycZQJpS7qYnPvALDHJgW JXgl0/JEXDBZ8LffFQlTqKOpjAnw9w/PPzGcHaxotPEwNh78LjnqkZfkjv3oTMVU/TBFbG 3/7lM3+jpTCX2L0NM+6rOsxbM/jhqNA= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-330-QEAzuamIONaJ3RKrxinzpw-1; Fri, 23 Sep 2022 10:34:15 -0400 X-MC-Unique: QEAzuamIONaJ3RKrxinzpw-1 Received: by mail-qt1-f198.google.com with SMTP id fz10-20020a05622a5a8a00b0035ce18717daso80188qtb.11 for ; Fri, 23 Sep 2022 07:34:15 -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=VcaCTXc0xTM/SOMVKl51uT+JebyIeyyruekAC+urGX0=; b=TgUAjNyMmxtFFGY+Gsft9GUKDa3ZIhnrzb3ttiU7rnizSC3oRVWH24hKDg4S1pSBue h4D0qcF3l1FaQzFSsd9JpQumvKu57Ui11i2ldpBanqO53KGDPSXPLiyqoWrTgQ85CAXl HpCGZn9iqswizQ4s8VmmCnip1fVYQxExTQL5U/MzdxjBl3uqE/IaYy0qnFKMEaABo3A1 0cDSoBKlx2WMyL4JdNEf9O+2p2WM3FVlrjtKR3kiNGKpw1Hzqu0ZqooN8qV1WA7itxgm PkXp8mDAuI6/go/1fZpQzP0C2ggV0q29/Ajud0rwSmDtpOIWHYDxQQCK97TUU3BQ7jXk D5Rg== X-Gm-Message-State: ACrzQf1EnleG9bMScvWw0gWcQ2akBKFsZYbZL4DjKDterJVT5r9n3gM6 u7a9bZ1jsNvYPxq21DYmygU18Hq+lj8OlpmKwzTFah8Ys00Vw3T6YVHHADd5WatlbcVzi2mUE/C xD1MmhZ+LoSYgtj0= X-Received: by 2002:a05:622a:164d:b0:35c:c465:911b with SMTP id y13-20020a05622a164d00b0035cc465911bmr7297080qtj.250.1663943654839; Fri, 23 Sep 2022 07:34:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4zo3txzKOB6jtbXVRxKoIHIQ4rk1oMiTl8+2UlnfthyZtxjXr7R09Rs5zMVC3KqotdmnDlRA== X-Received: by 2002:a05:622a:164d:b0:35c:c465:911b with SMTP id y13-20020a05622a164d00b0035cc465911bmr7297061qtj.250.1663943654620; Fri, 23 Sep 2022 07:34:14 -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 h8-20020a05620a244800b006ce813bb306sm5798668qkn.125.2022.09.23.07.34.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 07:34:14 -0700 (PDT) Date: Fri, 23 Sep 2022 10:34:12 -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=-3.9 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=unavailable 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 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"? > > --- 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"). Marek