From patchwork Wed Jan 29 13:47:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1230893 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-518493-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=aXY2sf7H; 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=R+HyWRrh; 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 4874Yw0njcz9sRR for ; Thu, 30 Jan 2020 00:48:03 +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=wi/tC6sqqUZe0/RgZptwY0BpFSzlGnYghQ4xSnoRr/OmdrqG/BRSk nHKNkBYKZQ80Lkm23/+QIYJ6U2D8kyddTWy7A/+kTRFlQezGso9SMtlsYI/sZept GeJfV2zyEJSiyohwwJ12z8qKtTWHnCBdUgIec+Bx9kJUTVUiY92/xc= 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=5L8H8wggmE6QPcK9YxIXVTrVfP8=; b=aXY2sf7HUT0xITGFaF7p VO74X83q/ITJL/MY69mvjkoqc5QhL940HbLVuw7tt59Vj6glDj5brSPQauSelLr4 FwwJoI0J0CppmuKB7wQbycxdXqCIX8vLIetXJE0P/IThcjeyYrt5ooL3ihM5ai/N fkNqGk7+V2DVV2WNjm+caOo= Received: (qmail 78789 invoked by alias); 29 Jan 2020 13:47:40 -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 78318 invoked by uid 89); 29 Jan 2020 13:47:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 Jan 2020 13:47:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580305644; 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=M0xZMZlxX8fi9SCsZZiQLHKrPICxZFyy8KGXrVf6o9Y=; b=R+HyWRrhlySP4ftd7d0BPd9oc+iYDu3GOB+PR9PVTWrJJwIyKd5zf5q6Zc9GbNglF+s71u fpNnmMoHySVBvrdKuSXcgAKxMPLcVP9u/ZJiF2KOxS5QTWxb3bQ82YcZkcRZRGJC0KTpSc H4WfHjwd+/1jacmslWVRbSyy/9kGjZg= 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-67-mddepmKIMh6d-X6BvbdEtQ-1; Wed, 29 Jan 2020 08:47:22 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EFE9A8017CC; Wed, 29 Jan 2020 13:47:20 +0000 (UTC) Received: from localhost (unknown [10.33.36.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DE095C290; Wed, 29 Jan 2020 13:47:20 +0000 (UTC) Date: Wed, 29 Jan 2020 13:47:19 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [COMMITTED] libstdc++: Make std::compare_three_way check if <=> is valid (PR 93479) Message-ID: <20200129134719.GA161274@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 Currently types that cannot be compared using <=> but which are convertible to pointers will be compared by converting to pointers first. They should not be comparable. PR libstdc++/93479 * libsupc++/compare (__3way_builtin_ptr_cmp): Require <=> to be valid. * testsuite/18_support/comparisons/object/93479.cc: New test. Tested powerpc64le-linux, committed to master. commit 83b0201035cfdc1d4d80153f4e19ec98cf059941 Author: Jonathan Wakely Date: Wed Jan 29 13:36:15 2020 +0000 libstdc++: Make std::compare_three_way check if <=> is valid (PR 93479) Currently types that cannot be compared using <=> but which are convertible to pointers will be compared by converting to pointers first. They should not be comparable. PR libstdc++/93479 * libsupc++/compare (__3way_builtin_ptr_cmp): Require <=> to be valid. * testsuite/18_support/comparisons/object/93479.cc: New test. diff --git a/libstdc++-v3/libsupc++/compare b/libstdc++-v3/libsupc++/compare index 117340ff184..aabd0c56530 100644 --- a/libstdc++-v3/libsupc++/compare +++ b/libstdc++-v3/libsupc++/compare @@ -525,7 +525,9 @@ namespace std // BUILTIN-PTR-THREE-WAY(T, U) template concept __3way_builtin_ptr_cmp - = convertible_to<_Tp, const volatile void*> + = requires(_Tp&& __t, _Up&& __u) + { static_cast<_Tp&&>(__t) <=> static_cast<_Up&&>(__u); } + && convertible_to<_Tp, const volatile void*> && convertible_to<_Up, const volatile void*> && ! requires(_Tp&& __t, _Up&& __u) { operator<=>(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u)); } diff --git a/libstdc++-v3/testsuite/18_support/comparisons/object/93479.cc b/libstdc++-v3/testsuite/18_support/comparisons/object/93479.cc new file mode 100644 index 00000000000..7da1df15848 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/comparisons/object/93479.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include + +void +test01() +{ + // PR libstdc++/93479 + int i[1]; + int j[1]; + std::compare_three_way{}(i, j); // { dg-error "no match" } +} + +void +test02() +{ + struct X + { + operator const char*() const noexcept { return "!"; } + void operator<=>(X) const = delete; + void operator<=>(const void*) const = delete; + } x; + std::compare_three_way{}(x, x); // { dg-error "no match" } + std::compare_three_way{}(x, ""); // { dg-error "no match" } + std::compare_three_way{}("", x); // { dg-error "no match" } +}