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.129.124]) by sourceware.org (Postfix) with ESMTPS id 989083857B8D for ; Fri, 23 Sep 2022 15:54:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 989083857B8D 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=1663948497; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pQJReTaGzW3rXGfl/AVuRIr6amxvGIX8oWwvtqM1zZA=; b=XC9l29rfha+CoCDw70xfHlD0leMiG2jWaSH7ZYvjxZxyLByAHrtOranr1QkWY8vSC15dFf 654mcGcEbRcIHR1fefFJQTLSa54gKlL/wbF818rYDASNcSnZCJH/Efxg3s8DjT9I9OzVS2 UmqJqcZMs16+o0uGeGYasXEQ0rzXDqk= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-563-JQtS_vNbNcaelc7ybEL5MQ-1; Fri, 23 Sep 2022 11:54:56 -0400 X-MC-Unique: JQtS_vNbNcaelc7ybEL5MQ-1 Received: by mail-qk1-f199.google.com with SMTP id k2-20020a05620a414200b006ceec443c8bso298331qko.14 for ; Fri, 23 Sep 2022 08:54:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=pQJReTaGzW3rXGfl/AVuRIr6amxvGIX8oWwvtqM1zZA=; b=P/KuQljy1LQsshYQ4D9WuybD3SgT7hpWVQ2U77aWl3IAXq+/8eu6PkcUn2hzWTJj3a kbQaaKkBAS3ki4dsUSNKc3NpAVKNKQOdQ0z7/aT6rxiMOQK9dmYwpLuSEmCT9C45JpIC xNoGKv5GaAnz5YKL5Jt1PFI+OlmKdRPMWbMO2wpf/UK1nZb3qOfuu1Nx5AvcDXQ+03il lm2I5VWH4ADfIx3Yu8sisN3v2sbyTzsqg6GNvrMmiWGd9wB0NKcKa8KWMrT2SzVbw60/ O1qfmY9HfbuHH14evj0POFIkmzeSpXEGTrPlY3Dkdqlq267UUItH/eRnU1KIUefuUSPs vZQA== X-Gm-Message-State: ACrzQf2LMOdG3kgU/O1Wv1ZuZGIxRc4kVRtoD2LUKI41jXrBQiLSeo6p 1Fud24t3wYocBqnZeDp3Cp4mZsOsVZ4c3ooLjUd4LydCb73XSbFeRW0lo6LZYgaWoxI5USsSqhb 7BuBxBRBLU2FtEws= X-Received: by 2002:a05:620a:24d6:b0:6cd:f25e:8745 with SMTP id m22-20020a05620a24d600b006cdf25e8745mr6238504qkn.332.1663948495550; Fri, 23 Sep 2022 08:54:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4R8EbUgGQ0lltMm5yIJbftPZjAqoaQdjD6zI3SwyjgyKnUiWxzeYABP3NkT/hKscsYxnI9Tg== X-Received: by 2002:a05:620a:24d6:b0:6cd:f25e:8745 with SMTP id m22-20020a05620a24d600b006cdf25e8745mr6238492qkn.332.1663948495228; Fri, 23 Sep 2022 08:54:55 -0700 (PDT) Received: from [192.168.1.101] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id dt10-20020a05620a478a00b006ce3cffa2c8sm6457013qkb.43.2022.09.23.08.54.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Sep 2022 08:54:54 -0700 (PDT) Message-ID: Date: Fri, 23 Sep 2022 11:54:53 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH] c++: Implement __is_{nothrow_,}convertible [PR106784] To: Marek Polacek Cc: GCC Patches , libstdc++ , Jonathan Wakely References: <20220922133900.142238-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,NICE_REPLY_A,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 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. >>> --- 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? The patch is OK. Jason