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 E9AE43857433 for ; Mon, 26 Sep 2022 15:51:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E9AE43857433 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=1664207493; 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=03h0wCpLrk6YZLAx+CjWV3kOJ78Yp7T7UkhESjIPkPM=; b=cynOjf9bWfvt2oHCX51ag5qqY9VfAE/7/N84AvpH7Kbh2gAWUF/JzZmV/t72dLT6/eQRoR aQsmQsSQFRsYrPDBGHsrY1lArhgEk2Gzut2u5y1mlYxJ6X8elsBGzA+lT4gBlS+n2SX6IJ Rp/Vg/Y6WiATonUH7giFo6qMBTZPvIY= 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-310-imAOkyqfOsi7_2OWE4Jwlg-1; Mon, 26 Sep 2022 11:51:32 -0400 X-MC-Unique: imAOkyqfOsi7_2OWE4Jwlg-1 Received: by mail-qk1-f199.google.com with SMTP id bk21-20020a05620a1a1500b006be9f844c59so5228021qkb.9 for ; Mon, 26 Sep 2022 08:51:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date; bh=03h0wCpLrk6YZLAx+CjWV3kOJ78Yp7T7UkhESjIPkPM=; b=mGdXpdJsY3T0C7xYlyUOpD2CaPEg74qtl1ecxm9DrWPnLwf54GlMUAMeULXOUTrseC yq7sCcS2WX5QfxL+PER+EiYcxtRxHhccehFfTlfm8TQpI6kHVmdmntQnKRqwWrRtYcR9 IU5Q7GjhPH0DNBEo/lAY7weicGCHQCl5LnW34vv0EieEQVqDl0kL0QqQ2UqcegyUOd0P 0LidUA3bl3yxuPt07CACqfDPAcnL1SX5ZtzjCwulAbIyT1UB1vRzuKrGZoq/+4GZDYxl QkgJSC6BKByZYDHBrbQJ9L7o7wxkvb6KTVXlWhQt2DqnHm6B5j8nWIqEskXIg1Cn1aRL ZKcQ== X-Gm-Message-State: ACrzQf0HVcZQmXLNmjwFHga/MegYlNNQ9f1fE5NQ2v99raJnYLS9TLcs mZURGgKbfxC4yPKSgDpq5YWQc3J1b3RuaOO6roFRkc7HaYl/dMFqYl13m+yYDvnGHSlO/MOTJuQ WMZF37HiyOLh2X4lPyw== X-Received: by 2002:ad4:5ca2:0:b0:4aa:9d05:2424 with SMTP id q2-20020ad45ca2000000b004aa9d052424mr17434494qvh.71.1664207492198; Mon, 26 Sep 2022 08:51:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM49v5lLzuswcnKjEL7l+3XLg7hWa3kY55/FrZg4upHv+jeVK2rcwQjJh+PvVh6FWla0p7eT1A== X-Received: by 2002:ad4:5ca2:0:b0:4aa:9d05:2424 with SMTP id q2-20020ad45ca2000000b004aa9d052424mr17434485qvh.71.1664207491978; Mon, 26 Sep 2022 08:51:31 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id h11-20020a05620a284b00b006bbc3724affsm11682511qkp.45.2022.09.26.08.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 08:51:31 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Mon, 26 Sep 2022 11:51:30 -0400 (EDT) To: Marek Polacek cc: GCC Patches , Jason Merrill , Jonathan Wakely Subject: Re: [PATCH] c++: Instantiate less when evaluating __is_convertible In-Reply-To: <20220926152258.20921-1-polacek@redhat.com> Message-ID: <22a3074f-0180-5ab6-5a9d-c27f8db507c7@idea> References: <20220926152258.20921-1-polacek@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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 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). 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 > >