From patchwork Sun Feb 9 13:56:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1235438 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519189-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=P2PF3LQd; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dew3ljWh; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48FrFN6tq6z9sP7 for ; Mon, 10 Feb 2020 00:57:10 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=MFTkqzsQDiSd9PYoWWunKmm2Dijz5CGunyw52VD8rFf2m1cFWnP1v HP70qiPFzEToxT4+NMBrsCjVSYH2USL5cyJXJKn685HDoaducq6dH4sARGJYxWCg l1b/tgqp/UOTMb1Bob6CtPrcEL2RO1TAeMynNyQOEMiJrSBMH45SsQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=+MlxvsAPbKtU0B9UpauxNIo93v4=; b=P2PF3LQdF3scTFpta/PX ACuvMshIOuvIItLbZSIvwfPC+BnQ24scmhZ3W3nhMXle4XSQPYmqVPkfo+76MU1e 3TaoXezusvPByu7x38nvorvnU+6CcyyCpWelzh4oXSGnXeCPuI4hAgx4Z/UZmsrI g08ijY/b68L5CvOTChciy78= Received: (qmail 57000 invoked by alias); 9 Feb 2020 13:56:53 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 56901 invoked by uid 89); 9 Feb 2020 13:56:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (207.211.31.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 09 Feb 2020 13:56:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581256592; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=jcaYSq4OpWqbkc59GEk3tCxhXgeaCnXkkBEs3vPBWM4=; b=dew3ljWhDfncI8Z2LZjYYXnKHdUsp6EGCXoZ7p2VEdJKxJpAtvfQ4brX0YhQsBbwgo/M4/ YHIirxumlhkElgvG+lUXq1SrHfcKvmWPfDnXP5PiYtw+3myTkKnrq3icV4M8NmHLitRoFk bRzhSbJezvolWUSmTl9JvE1DrjYbKdU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-329-0FGxsYK2Pn2x0eKMjedhVQ-1; Sun, 09 Feb 2020 08:56:28 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A81B513E4; Sun, 9 Feb 2020 13:56:27 +0000 (UTC) Received: from localhost (unknown [10.33.36.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E6FA19C58; Sun, 9 Feb 2020 13:56:27 +0000 (UTC) Date: Sun, 9 Feb 2020 13:56:26 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix BUILTIN-PTR-CMP helpers Message-ID: <20200209135626.GA1239883@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline The helpers that implement BUILTIN-PTR-CMP do not currently check if the arguments are actually comparable, so the concept is true when it shouldn't be. Since we're trying to test for an unambiguous conversion to pointers, we can also require that it returns bool, because the built-in comparisons for pointers do return bool. * include/bits/range_cmp.h (__detail::__eq_builtin_ptr_cmp): Require equality comparison to be valid and return bool. (__detail::__less_builtin_ptr_cmp): Likewise for less-than comparison. * testsuite/20_util/function_objects/range.cmp/equal_to.cc: Check type with ambiguous conversion to fundamental types. * testsuite/20_util/function_objects/range.cmp/less.cc: Likewise. Tested powerpc64le-linux, committed to master. commit dcda050e6c3c3726cb14109674053f83cae330be Author: Jonathan Wakely Date: Sun Feb 9 13:37:43 2020 +0000 libstdc++: Fix BUILTIN-PTR-CMP helpers The helpers that implement BUILTIN-PTR-CMP do not currently check if the arguments are actually comparable, so the concept is true when it shouldn't be. Since we're trying to test for an unambiguous conversion to pointers, we can also require that it returns bool, because the built-in comparisons for pointers do return bool. * include/bits/range_cmp.h (__detail::__eq_builtin_ptr_cmp): Require equality comparison to be valid and return bool. (__detail::__less_builtin_ptr_cmp): Likewise for less-than comparison. * testsuite/20_util/function_objects/range.cmp/equal_to.cc: Check type with ambiguous conversion to fundamental types. * testsuite/20_util/function_objects/range.cmp/less.cc: Likewise. diff --git a/libstdc++-v3/include/bits/range_cmp.h b/libstdc++-v3/include/bits/range_cmp.h index e0385035543..571ba7f9555 100644 --- a/libstdc++-v3/include/bits/range_cmp.h +++ b/libstdc++-v3/include/bits/range_cmp.h @@ -62,7 +62,8 @@ namespace ranges // BUILTIN-PTR-CMP(T, ==, U) template concept __eq_builtin_ptr_cmp - = convertible_to<_Tp, const volatile void*> + = requires (_Tp&& __t, _Up&& __u) { { __t == __u } -> same_as; } + && convertible_to<_Tp, const volatile void*> && convertible_to<_Up, const volatile void*> && (! requires(_Tp&& __t, _Up&& __u) { operator==(std::forward<_Tp>(__t), std::forward<_Up>(__u)); } @@ -73,7 +74,8 @@ namespace ranges // BUILTIN-PTR-CMP(T, <, U) template concept __less_builtin_ptr_cmp - = convertible_to<_Tp, const volatile void*> + = requires (_Tp&& __t, _Up&& __u) { { __t < __u } -> same_as; } + && convertible_to<_Tp, const volatile void*> && convertible_to<_Up, const volatile void*> && (! requires(_Tp&& __t, _Up&& __u) { operator<(std::forward<_Tp>(__t), std::forward<_Up>(__u)); } diff --git a/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/equal_to.cc b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/equal_to.cc index 39bc984c508..34f8ee5aca4 100644 --- a/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/equal_to.cc +++ b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/equal_to.cc @@ -69,6 +69,15 @@ test02() VERIFY( f(x, x) ); } +struct Y +{ + operator void*() const; + operator int() const; +}; + +// X{} == X{} is ambiguous so ranges::equal_to{}(X{}, X{}) should be invalid +static_assert( !std::is_invocable_v ); + int main() { diff --git a/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/less.cc b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/less.cc index 978894d5fc0..bf7d600e7fe 100644 --- a/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/less.cc +++ b/libstdc++-v3/testsuite/20_util/function_objects/range.cmp/less.cc @@ -74,6 +74,15 @@ test02() VERIFY( ! f(x, x) ); } +struct Y +{ + operator void*() const; + operator int() const; +}; + +// X{} == X{} is ambiguous so ranges::less{}(X{}, X{}) should be invalid +static_assert( !std::is_invocable_v ); + int main() {