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 209F23858C62 for ; Mon, 26 Sep 2022 16:22:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 209F23858C62 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=1664209322; 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=DLkW2D2cnLDUhuBJosAXJN1XGkLQga+fJigoDSmmzVI=; b=CjNkf4PvcyuyQ3Rs0TltLNvLOwj8fi4vfgl4eVP8Tuvjzg2QJgc4TSu0oXO7RSRFuxqGL0 5K0JsJu4ezPeF1nDPop7xg4gAN+lZUS1vRi0Kx6R10aZYI0Q3asXXaqwZS/ESskQGwbj8z Jp2XYnVArRF8iTO9ClmJhKJtYvS2S6M= 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-42-rVkvcI4SMXyOQEEggV5K6g-1; Mon, 26 Sep 2022 12:22:02 -0400 X-MC-Unique: rVkvcI4SMXyOQEEggV5K6g-1 Received: by mail-qv1-f71.google.com with SMTP id g12-20020a0cfdcc000000b004ad431ceee0so4079376qvs.7 for ; Mon, 26 Sep 2022 09:22:02 -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=DLkW2D2cnLDUhuBJosAXJN1XGkLQga+fJigoDSmmzVI=; b=Vsb69OPPR/XkzZ+uCG19tbxGu+g530DLGebePcON6ggQQlIXb44HgWSAKeCRhRcVlm 1ES7MUXdAFuNaGO8Z4CeET89xa1YwEyYPWDtoDS25t6TSd/qnyoRkHh0Z88cvJNDQDCD 1ze/+6i6l1RURx5mOqnqueAuVdmOpo3/2F36DDoXZ+uURY8WpMNoTGpE4QypQVAONK60 z4O9b9yJ6DJb3u5Z+GjmBiExw3yakE21k6z2C6r1hYtUHb5z0vsupleqp1r6NL87RRSn nrjxoIKeX1ddvVo+cl+BOB6JyaSw+6+gyaikH56WUsSUwyymn2Ao5FTr/JAwUjT6SRu9 vCGw== X-Gm-Message-State: ACrzQf1XSi60EkLSnAvZEz/RQeSafztAMzVu0TJp2JWRaKgUxyFQpY0M fkpcWkmBIyOXB68ip2HBqqiYsI1ZVK2pPHEhx2AnVMUs7cstWV2jw3f3aMS1uqCn23iJkR/QYKC nEINgq199VDuk9+eLBQ== X-Received: by 2002:a37:5ac5:0:b0:6cf:7c04:118e with SMTP id o188-20020a375ac5000000b006cf7c04118emr9948253qkb.215.1664209321322; Mon, 26 Sep 2022 09:22:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7e4tcgFH1HJaqAAt3DrNTAK0iWsLAAUNGwWx6VGnNlus+sxmUMXg90q7rSxCLcMBTA9SdkMg== X-Received: by 2002:a37:5ac5:0:b0:6cf:7c04:118e with SMTP id o188-20020a375ac5000000b006cf7c04118emr9948239qkb.215.1664209321051; Mon, 26 Sep 2022 09:22:01 -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 cf14-20020a05622a400e00b0031f41ea94easm10966555qtb.28.2022.09.26.09.22.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Sep 2022 09:22:00 -0700 (PDT) Message-ID: <27212f50-5b2b-0a7b-48fd-87de89fe2da3@redhat.com> Date: Mon, 26 Sep 2022 12:21:59 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.1 Subject: Re: [PATCH] c++: Instantiate less when evaluating __is_convertible To: Patrick Palka , Marek Polacek Cc: GCC Patches , Jonathan Wakely References: <20220926152258.20921-1-polacek@redhat.com> <22a3074f-0180-5ab6-5a9d-c27f8db507c7@idea> From: Jason Merrill In-Reply-To: <22a3074f-0180-5ab6-5a9d-c27f8db507c7@idea> 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=-13.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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/26/22 11:51, Patrick Palka wrote: > On Mon, 26 Sep 2022, Marek Polacek via Gcc-patches wrote: > >> Jon reported that evaluating __is_convertible in this test leads to >> instantiating char_traits::eq, which is invalid (because we >> are trying to call a member function on a char) and so we fail to >> compile the test. __is_convertible doesn't and shouldn't need to >> instantiate so much, so let's limit it with a cp_unevaluated guard. >> >> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? >> >> PR c++/106784 >> >> gcc/cp/ChangeLog: >> >> * method.cc (is_convertible): Use cp_unevaluated. > > I think is_nothrow_convertible would need cp_unevaluated too (or maybe we > should define is_nothrow_convertible in terms of is_convertible). Agreed. > And the testcase can probably be minimized to something like: > > struct A; > struct B { template B(const T&) noexcept { T::nonexistent; } }; > > static_assert(__is_convertible(const A&, B)); > static_assert(__is_nothrow_convertible(const A&, B)); > >> >> gcc/testsuite/ChangeLog: >> >> * g++.dg/ext/is_convertible3.C: New test. >> --- >> gcc/cp/method.cc | 1 + >> gcc/testsuite/g++.dg/ext/is_convertible3.C | 66 ++++++++++++++++++++++ >> 2 files changed, 67 insertions(+) >> create mode 100644 gcc/testsuite/g++.dg/ext/is_convertible3.C >> >> diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc >> index c35a59fe56c..45f70f5d3f3 100644 >> --- a/gcc/cp/method.cc >> +++ b/gcc/cp/method.cc >> @@ -2246,6 +2246,7 @@ is_convertible (tree from, tree to) >> { >> if (VOID_TYPE_P (from) && VOID_TYPE_P (to)) >> return true; >> + cp_unevaluated u; >> tree expr = build_stub_object (from); >> expr = perform_implicit_conversion (to, expr, tf_none); >> if (expr == error_mark_node) >> diff --git a/gcc/testsuite/g++.dg/ext/is_convertible3.C b/gcc/testsuite/g++.dg/ext/is_convertible3.C >> new file mode 100644 >> index 00000000000..c817dc6f146 >> --- /dev/null >> +++ b/gcc/testsuite/g++.dg/ext/is_convertible3.C >> @@ -0,0 +1,66 @@ >> +// PR c++/106784 >> +// { dg-do compile { target c++11 } } >> +// Make sure we don't reject this at runtime by trying to instantiate >> +// char_traits::eq(CharT, CharT) while evaluating __is_convertible. >> + >> +template >> +struct bool_constant { static constexpr bool value = B; }; >> +using true_type = bool_constant; >> +using false_type = bool_constant; >> + >> +template struct is_void : false_type { }; >> +template<> struct is_void : true_type { }; >> + >> +template T&& declval(); >> + >> +template struct enable_if { }; >> +template<> struct enable_if { using type = void; }; >> +template using enable_if_t = typename enable_if::type; >> + >> +template >> + struct is_convertible >> + : public bool_constant<__is_convertible(_From, _To)> >> + { }; >> + >> +template >> +struct char_traits >> +{ >> + static unsigned long length(const char* s) { eq(*s, *s); return 0; } >> + >> + static void eq(CharT l, CharT r) noexcept { l.f(r); } >> +}; >> + >> +template >> +struct basic_string_view >> +{ >> + using traits_type = char_traits; >> + >> + constexpr basic_string_view() = default; >> + constexpr basic_string_view(const basic_string_view&) = default; >> + >> + constexpr >> + basic_string_view(const CharT* __str) noexcept >> + : _M_len{traits_type::length(__str)} >> + { } >> + >> + unsigned long _M_len = 0; >> +}; >> + >> +template >> +struct basic_string >> +{ >> + template >> + enable_if_t>::value >> + && !is_convertible::value> >> + replace(int, T) { } >> + >> + void replace(unsigned long, const char*) { } >> + >> + void replace(const char* s) { replace(1, s); } >> +}; >> + >> +int main() >> +{ >> + basic_string s; >> + s.replace(""); >> +} >> >> base-commit: 2460f7cdef7ef9c971de79271afc0db73687a272 >> -- >> 2.37.3 >> >> >