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 E65013858C39 for ; Mon, 26 Sep 2022 15:23:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E65013858C39 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=1664205788; 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; bh=H9DXccxLrbMN7Iu04szs6RtqsV337f2kmVxf1oh39b4=; b=FE5Yj161KdA6HRaCb+uGqPwN4vDHldjw7IFsopod9PF5Lfkl5SKGnmxAW/owewDpUkyByL 0NAsVsE3Svl4AJxTfexCa9qrIHlSC5ZT9F1hnk37qsRwaaZjyKg7j5Y4+6Y1xDmXJhYKxi Tihh5Abb+zop9BCLOKmMe3MyWYf91Rc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-387-23D8GWpiNG2vsMGHjuqQ3Q-1; Mon, 26 Sep 2022 11:23:07 -0400 X-MC-Unique: 23D8GWpiNG2vsMGHjuqQ3Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0362685A5B6 for ; Mon, 26 Sep 2022 15:23:07 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.9.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1FFF2166B2C; Mon, 26 Sep 2022 15:23:06 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Cc: Jonathan Wakely Subject: [PATCH] c++: Instantiate less when evaluating __is_convertible Date: Mon, 26 Sep 2022 11:22:58 -0400 Message-Id: <20220926152258.20921-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.6 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_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: 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. 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