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 28AD63857434 for ; Fri, 23 Sep 2022 16:34:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 28AD63857434 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-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-414-xceqLiDsNhmG0oSYUCdq-g-1; Fri, 23 Sep 2022 12:34:33 -0400 X-MC-Unique: xceqLiDsNhmG0oSYUCdq-g-1 Received: by mail-qt1-f198.google.com with SMTP id s21-20020a05622a1a9500b0035bb9e79172so289289qtc.20 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=GgBS5UJ2ReChm510uVxVvqggvwsRxXADDiLvrKgvaRlHf+90DQ0E+udLLZcYgf8nYD btNje3pTEoYU7inEA+jmSlHtxTMi7RbfeE/kCAbaCYFwJMD4UB87/XouZ1kdsNRms3+G TvXYc8zcnhx8krFkCfR0vgKXUbo/WnsSl8qh7rdqg4hwgGeJMCW/Zeaa85PpOhRDTuYj 73sE/KL7MbZATCMzygcWIwXACh2E7gvi0rZEcn9FKm3mEvrDb/6Yrhmf67SV+fVqi05x VVIhA0QlPNrWvluxv1ftXukVU6IU+m+bmO8VCwlDeBfJ9P4QqiewLqsv1e1fdthtVjyT FxKA== X-Gm-Message-State: ACrzQf2REd9BlL3Y147SY41xXClViWi4hssJQQvAz5a8KptpSdA9CeC9 0JZ+EMejCbVHdLXbMrTVdydW45e6mJ5EF4fNMvIoDUkWA1BASFvQSu0IzHl8cQze415tCPicy0W IVFQmAyLMqxtLUikUsg7cmTd+mCCfsgM= X-Received: by 2002:a05:622a:408a:b0:35b:b5fa:5e32 with SMTP id cg10-20020a05622a408a00b0035bb5fa5e32mr7872367qtb.122.1663950873117; 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.7 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=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 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.