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 C98B1385740B for ; Fri, 23 Sep 2022 16:34:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C98B1385740B 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=1663950874; 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=9Khf59Ro23+XO7V9/XxKy0rzWgIFQMlI1Ra4QfmG054=; b=gS0pOfrzkQWuRFqepV4JRcmFc8AXy/CaTILrYCFsUKQxLSpwyngxnF0YjLt79ZSpVuIXhl QGDRqy1GYygyR/Z8SSFrFx+UL991VqVboLRdM/u/h5zQpKpxxSkgKplszMDzCesbx43y+A xV0+XqCEt1h7ezvczzAxGtjoeJA1qbs= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-593-95wnKezBOeG6_NQtq0CMXw-1; Fri, 23 Sep 2022 12:34:33 -0400 X-MC-Unique: 95wnKezBOeG6_NQtq0CMXw-1 Received: by mail-qt1-f200.google.com with SMTP id g6-20020ac84b66000000b0035cf832dec9so315151qts.6 for ; Fri, 23 Sep 2022 09:34:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=9Khf59Ro23+XO7V9/XxKy0rzWgIFQMlI1Ra4QfmG054=; b=apYBtAHtqEKQGzpl3I7aKosTx/bFnOfVEZq+dXNcJnUDpvXIa3GBh0FgwQ2ZZYGbj5 qhpA8XJv2tRpeZzFeJ8i7aEqB220ALgWCyXbe4Te3zGDvjfKAvepTOiY03CrlCFBfzrW laxFiJ9pqA46OJCYqvPje5IS41yFzyHlrepBk76+OIjtXQ7N5QCPgjlZUVs2iY5RWacy RQARPNzDQlWTIwu6Wg0LJOCQZAseEX5Ecj40xdsyMnIi/Nm/NRHkDnWHqNPofmezRwdV xWQSaLrHJ43vrCPB1rO2UZ2aa3dW0LkjmYrqi0DBbozBQbKzU1U0T5kZPKiLau02WzLd 3D0g== X-Gm-Message-State: ACrzQf2gAO71/xYlzkHuQk+pqpsUAvWr8maSNjUFYfxpIsPwsgnxJETA Y/0ZseEfraGgz+tPqo++ay+WGebuY67vbDq91IDL7+NIElcS4GTDSIOGO7qYSLzX61abxaWX+2h SH4//SZnHmg31z8Ney4mZNxkF65bBkQoiiQ== X-Received: by 2002:a05:622a:408a:b0:35b:b5fa:5e32 with SMTP id cg10-20020a05622a408a00b0035bb5fa5e32mr7872361qtb.122.1663950873087; Fri, 23 Sep 2022 09:34:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5CsEmX75ND93ueHTgK2wdIo1g98hp091yLoTMQUBIU6ZOBkluLM6OEBRKFDWwYD6Llw4HHxP9prvrtb6Hkl2w= X-Received: by 2002:a05:622a:408a:b0:35b:b5fa:5e32 with SMTP id cg10-20020a05622a408a00b0035bb5fa5e32mr7872340qtb.122.1663950872888; Fri, 23 Sep 2022 09:34:32 -0700 (PDT) MIME-Version: 1.0 References: <20220922133900.142238-1-polacek@redhat.com> In-Reply-To: From: Jonathan Wakely Date: Fri, 23 Sep 2022 17:34:21 +0100 Message-ID: Subject: Re: [PATCH] c++: Implement __is_{nothrow_,}convertible [PR106784] To: Marek Polacek Cc: Jason Merrill , GCC Patches , "libstdc++" X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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, 23 Sept 2022 at 15:43, Jonathan Wakely wrote: > > On Fri, 23 Sept 2022 at 15: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. > > That's fine, the type traits in libstdc++ are always "a context > unrelated to either type", unless users do something idiotic like > declare std::is_assignable as a friend. > > https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1339r1.pdf > wants to explicitly say that's idiotic. And I just checked that a variable template like std::is_assignable_v also counts as "a context unrelated to either type", even when instantiated inside a member function of the type: #include template constexpr bool is_assignable_v = __is_assignable(T, U); class S { operator int(); friend void g(); // #1 }; void g () { // #1 doesn't matter static_assert(std::is_assignable::value, ""); static_assert(std::is_assignable_v, ""); static_assert(__is_assignable(int&, S), ""); } The first two assertions are consistent, and fail, which is what we want. The direct use of the built-in succeeds, but we don't care.