From patchwork Wed Apr 17 16:07:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1087038 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-499392-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.b="PGYb7Fv4"; 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 44knGB2DPnz9s4V for ; Thu, 18 Apr 2019 02:08:12 +1000 (AEST) 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=f46/G4xOhjvRTJtNCuZkPe5r2qtxXDWCSNX/g25lw4BnuNCZZscdr Dy8nfj4WW7ZYW16f0are5F0FYsXtaIMjMSi+dwiW9uvnoCBbt+V2/3awjl8EPePL W624PEK8g8RAM/R2DZ4I7bvag1wnoayHGws+IrGgooGsrWjOfKQ+Sw= 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=/wJT7/HPcM8VX9YOzA+H7VcbkMw=; b=PGYb7Fv4CfFuz80d9f90 ogICI1d/JeCG0gUIeH2veJLN7dERU0LftI4I1kMsQfPljW3eU5yp5sgSpyt7LA8W 8U5R87ljV9TGIRuuDu/zAzfcfWWxymMv6dAxa+hCb1uRX9MBKIayl2U7Lj7KMV4t kGatR0fIRToqLpedIKGu7kc= Received: (qmail 5494 invoked by alias); 17 Apr 2019 16:07:57 -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 5479 invoked by uid 89); 17 Apr 2019 16:07:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 17 Apr 2019 16:07:56 +0000 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 mx1.redhat.com (Postfix) with ESMTPS id C9287C067856; Wed, 17 Apr 2019 16:07:45 +0000 (UTC) Received: from localhost (unknown [10.33.36.125]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6547319C58; Wed, 17 Apr 2019 16:07:44 +0000 (UTC) Date: Wed, 17 Apr 2019 17:07:43 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 1/3] Fix tests for std::variant to match original intention Message-ID: <20190417160743.GA31346@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.11.3 (2019-02-01) * testsuite/20_util/variant/compile.cc (MoveCtorOnly): Fix type to actually match its name. (MoveCtorAndSwapOnly): Define new type that adds swap to MoveCtorOnly. (test_swap()): Fix result for MoveCtorOnly and check MoveCtorAndSwapOnly. Tested powerpc64le-linux. commit 855e2fb029adf77f6189f01b1a8d86dc2cca2464 Author: Jonathan Wakely Date: Wed Apr 17 14:55:39 2019 +0100 Fix tests for std::variant to match original intention * testsuite/20_util/variant/compile.cc (MoveCtorOnly): Fix type to actually match its name. (MoveCtorAndSwapOnly): Define new type that adds swap to MoveCtorOnly. (test_swap()): Fix result for MoveCtorOnly and check MoveCtorAndSwapOnly. diff --git a/libstdc++-v3/testsuite/20_util/variant/compile.cc b/libstdc++-v3/testsuite/20_util/variant/compile.cc index 04fef0be13f..5a2d91709a0 100644 --- a/libstdc++-v3/testsuite/20_util/variant/compile.cc +++ b/libstdc++-v3/testsuite/20_util/variant/compile.cc @@ -54,12 +54,15 @@ struct DefaultNoexcept struct MoveCtorOnly { MoveCtorOnly() noexcept = delete; - MoveCtorOnly(const DefaultNoexcept&) noexcept = delete; - MoveCtorOnly(DefaultNoexcept&&) noexcept { } - MoveCtorOnly& operator=(const DefaultNoexcept&) noexcept = delete; - MoveCtorOnly& operator=(DefaultNoexcept&&) noexcept = delete; + MoveCtorOnly(const MoveCtorOnly&) noexcept = delete; + MoveCtorOnly(MoveCtorOnly&&) noexcept { } + MoveCtorOnly& operator=(const MoveCtorOnly&) noexcept = delete; + MoveCtorOnly& operator=(MoveCtorOnly&&) noexcept = delete; }; +struct MoveCtorAndSwapOnly : MoveCtorOnly { }; +void swap(MoveCtorAndSwapOnly&, MoveCtorAndSwapOnly&) { } + struct nonliteral { nonliteral() { } @@ -259,7 +262,8 @@ static_assert( !std::is_swappable_v> ); void test_swap() { static_assert(is_swappable_v>, ""); - static_assert(is_swappable_v>, ""); + static_assert(!is_swappable_v>, ""); + static_assert(is_swappable_v>, ""); static_assert(!is_swappable_v>, ""); } From patchwork Wed Apr 17 16:09:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1087039 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-499393-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.b="Y7skBohE"; 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 44knJB54gDz9s3q for ; Thu, 18 Apr 2019 02:10:02 +1000 (AEST) 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:references:mime-version:content-type :in-reply-to; q=dns; s=default; b=M8FE/+aWdT+m7NGBx9Tr0PKGDr3lPs lunQsVUaee7BQmM5IfIjP1nJiFElEfef5uJNId7XaNLmExVslhGURgmHqOvMm8U4 /3z47SzCF+sPSHjiyHFEPHJjWKBoma/vIyELLSoN7HxwfEuUAahLP4ibGXd7MPYz UCMRGjKoX2fKg= 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:references:mime-version:content-type :in-reply-to; s=default; bh=7PIIxOljeJBuQjzQbyL4qsVbzdI=; b=Y7sk BohE4KTWt09o3yP0/CT8vIFSa4JhvO5R4AasQFor51mDreCzWfLE2isFgcDdWBLO jTiiTdaWvErQlAgqAyeWbDTqrv3n9tRCxo5Zj4UGSx+6p7RnEb3QJEexeSXJDXAE +IuJFtcfNowaJZv19FPxmo7tIgOTkvDCxR6W3Pc= Received: (qmail 15876 invoked by alias); 17 Apr 2019 16:09:46 -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 15855 invoked by uid 89); 17 Apr 2019 16:09:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=visit X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 17 Apr 2019 16:09:44 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DC6E472652; Wed, 17 Apr 2019 16:09:42 +0000 (UTC) Received: from localhost (unknown [10.33.36.125]) by smtp.corp.redhat.com (Postfix) with ESMTP id 683D860143; Wed, 17 Apr 2019 16:09:42 +0000 (UTC) Date: Wed, 17 Apr 2019 17:09:41 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 2/3] Remove unnecessary string literals from static_assert in C++17 tests Message-ID: <20190417160941.GX943@redhat.com> References: <20190417160743.GA31346@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190417160743.GA31346@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.11.3 (2019-02-01) Remove unnecessary string literals from static_assert in C++17 tests The string literal is optional in C++17 and all these are empty so add no value. Tested powerpc64le-linux. commit 028676a32fa51c0116e3c117a36550dd04cd39fe Author: Jonathan Wakely Date: Wed Apr 17 14:57:41 2019 +0100 Remove unnecessary string literals from static_assert in C++17 tests The string literal is optional in C++17 and all these are empty so add no value. * testsuite/20_util/variant/compile.cc: Remove empty string literals from static_assert declarations. diff --git a/libstdc++-v3/testsuite/20_util/variant/compile.cc b/libstdc++-v3/testsuite/20_util/variant/compile.cc index 5a2d91709a0..b67c98adf4a 100644 --- a/libstdc++-v3/testsuite/20_util/variant/compile.cc +++ b/libstdc++-v3/testsuite/20_util/variant/compile.cc @@ -77,59 +77,59 @@ struct nonliteral void default_ctor() { - static_assert(is_default_constructible_v>, ""); - static_assert(is_default_constructible_v>, ""); - static_assert(!is_default_constructible_v>, ""); - static_assert(is_default_constructible_v>, ""); + static_assert(is_default_constructible_v>); + static_assert(is_default_constructible_v>); + static_assert(!is_default_constructible_v>); + static_assert(is_default_constructible_v>); - static_assert(noexcept(variant()), ""); - static_assert(!noexcept(variant()), ""); - static_assert(noexcept(variant()), ""); + static_assert(noexcept(variant())); + static_assert(!noexcept(variant())); + static_assert(noexcept(variant())); } void copy_ctor() { - static_assert(is_copy_constructible_v>, ""); - static_assert(!is_copy_constructible_v>, ""); - static_assert(is_trivially_copy_constructible_v>, ""); - static_assert(!is_trivially_copy_constructible_v>, ""); + static_assert(is_copy_constructible_v>); + static_assert(!is_copy_constructible_v>); + static_assert(is_trivially_copy_constructible_v>); + static_assert(!is_trivially_copy_constructible_v>); { variant a; - static_assert(noexcept(variant(a)), ""); + static_assert(noexcept(variant(a))); } { variant a; - static_assert(!noexcept(variant(a)), ""); + static_assert(!noexcept(variant(a))); } { variant a; - static_assert(!noexcept(variant(a)), ""); + static_assert(!noexcept(variant(a))); } { variant a; - static_assert(noexcept(variant(a)), ""); + static_assert(noexcept(variant(a))); } } void move_ctor() { - static_assert(is_move_constructible_v>, ""); - static_assert(!is_move_constructible_v>, ""); - static_assert(is_trivially_move_constructible_v>, ""); - static_assert(!is_trivially_move_constructible_v>, ""); - static_assert(!noexcept(variant(declval>())), ""); - static_assert(noexcept(variant(declval>())), ""); + static_assert(is_move_constructible_v>); + static_assert(!is_move_constructible_v>); + static_assert(is_trivially_move_constructible_v>); + static_assert(!is_trivially_move_constructible_v>); + static_assert(!noexcept(variant(declval>()))); + static_assert(noexcept(variant(declval>()))); } void arbitrary_ctor() { - static_assert(!is_constructible_v, const char*>, ""); - static_assert(is_constructible_v, const char*>, ""); - static_assert(noexcept(variant(int{})), ""); - static_assert(noexcept(variant(int{})), ""); - static_assert(!noexcept(variant(Empty{})), ""); - static_assert(noexcept(variant(DefaultNoexcept{})), ""); + static_assert(!is_constructible_v, const char*>); + static_assert(is_constructible_v, const char*>); + static_assert(noexcept(variant(int{}))); + static_assert(noexcept(variant(int{}))); + static_assert(!noexcept(variant(Empty{}))); + static_assert(noexcept(variant(DefaultNoexcept{}))); } void in_place_index_ctor() @@ -142,105 +142,105 @@ void in_place_type_ctor() { variant a(in_place_type, "a"); variant b(in_place_type, {'a'}); - static_assert(!is_constructible_v, in_place_type_t, const char*>, ""); + static_assert(!is_constructible_v, in_place_type_t, const char*>); } void dtor() { - static_assert(is_destructible_v>, ""); - static_assert(is_destructible_v>, ""); + static_assert(is_destructible_v>); + static_assert(is_destructible_v>); } void copy_assign() { - static_assert(is_copy_assignable_v>, ""); - static_assert(!is_copy_assignable_v>, ""); - static_assert(is_trivially_copy_assignable_v>, ""); - static_assert(!is_trivially_copy_assignable_v>, ""); + static_assert(is_copy_assignable_v>); + static_assert(!is_copy_assignable_v>); + static_assert(is_trivially_copy_assignable_v>); + static_assert(!is_trivially_copy_assignable_v>); { variant a; - static_assert(!noexcept(a = a), ""); + static_assert(!noexcept(a = a)); } { variant a; - static_assert(noexcept(a = a), ""); + static_assert(noexcept(a = a)); } } void move_assign() { - static_assert(is_move_assignable_v>, ""); - static_assert(!is_move_assignable_v>, ""); - static_assert(is_trivially_move_assignable_v>, ""); - static_assert(!is_trivially_move_assignable_v>, ""); + static_assert(is_move_assignable_v>); + static_assert(!is_move_assignable_v>); + static_assert(is_trivially_move_assignable_v>); + static_assert(!is_trivially_move_assignable_v>); { variant a; - static_assert(!noexcept(a = std::move(a)), ""); + static_assert(!noexcept(a = std::move(a))); } { variant a; - static_assert(noexcept(a = std::move(a)), ""); + static_assert(noexcept(a = std::move(a))); } } void arbitrary_assign() { - static_assert(!is_assignable_v, const char*>, ""); - static_assert(is_assignable_v, const char*>, ""); - static_assert(noexcept(variant() = int{}), ""); - static_assert(noexcept(variant() = int{}), ""); - static_assert(!noexcept(variant() = Empty{}), ""); - static_assert(noexcept(variant() = DefaultNoexcept{}), ""); + static_assert(!is_assignable_v, const char*>); + static_assert(is_assignable_v, const char*>); + static_assert(noexcept(variant() = int{})); + static_assert(noexcept(variant() = int{})); + static_assert(!noexcept(variant() = Empty{})); + static_assert(noexcept(variant() = DefaultNoexcept{})); } void test_get() { - static_assert(is_same(variant())), int&&>::value, ""); - static_assert(is_same(variant())), string&&>::value, ""); - static_assert(is_same(variant())), const string&&>::value, ""); + static_assert(is_same(variant())), int&&>::value); + static_assert(is_same(variant())), string&&>::value); + static_assert(is_same(variant())), const string&&>::value); - static_assert(is_same(variant())), int&&>::value, ""); - static_assert(is_same(variant())), string&&>::value, ""); - static_assert(is_same(variant())), const string&&>::value, ""); + static_assert(is_same(variant())), int&&>::value); + static_assert(is_same(variant())), string&&>::value); + static_assert(is_same(variant())), const string&&>::value); } void test_relational() { { constexpr variant a(42), b(43); - static_assert((a < b), ""); - static_assert(!(a > b), ""); - static_assert((a <= b), ""); - static_assert(!(a == b), ""); - static_assert((a != b), ""); - static_assert(!(a >= b), ""); + static_assert((a < b)); + static_assert(!(a > b)); + static_assert((a <= b)); + static_assert(!(a == b)); + static_assert((a != b)); + static_assert(!(a >= b)); } { constexpr variant a(42), b(42); - static_assert(!(a < b), ""); - static_assert(!(a > b), ""); - static_assert((a <= b), ""); - static_assert((a == b), ""); - static_assert(!(a != b), ""); - static_assert((a >= b), ""); + static_assert(!(a < b)); + static_assert(!(a > b)); + static_assert((a <= b)); + static_assert((a == b)); + static_assert(!(a != b)); + static_assert((a >= b)); } { constexpr variant a(43), b(42); - static_assert(!(a < b), ""); - static_assert((a > b), ""); - static_assert(!(a <= b), ""); - static_assert(!(a == b), ""); - static_assert((a != b), ""); - static_assert((a >= b), ""); + static_assert(!(a < b)); + static_assert((a > b)); + static_assert(!(a <= b)); + static_assert(!(a == b)); + static_assert((a != b)); + static_assert((a >= b)); } { constexpr monostate a, b; - static_assert(!(a < b), ""); - static_assert(!(a > b), ""); - static_assert((a <= b), ""); - static_assert((a == b), ""); - static_assert(!(a != b), ""); - static_assert((a >= b), ""); + static_assert(!(a < b)); + static_assert(!(a > b)); + static_assert((a <= b)); + static_assert((a == b)); + static_assert(!(a != b)); + static_assert((a >= b)); } } @@ -261,10 +261,10 @@ static_assert( !std::is_swappable_v> ); void test_swap() { - static_assert(is_swappable_v>, ""); - static_assert(!is_swappable_v>, ""); - static_assert(is_swappable_v>, ""); - static_assert(!is_swappable_v>, ""); + static_assert(is_swappable_v>); + static_assert(!is_swappable_v>); + static_assert(is_swappable_v>); + static_assert(!is_swappable_v>); } void test_visit() @@ -297,7 +297,7 @@ void test_visit() constexpr bool operator()(const int&) { return true; } constexpr bool operator()(const nonliteral&) { return false; } }; - static_assert(visit(Visitor(), variant(0)), ""); + static_assert(visit(Visitor(), variant(0))); } { struct Visitor @@ -305,7 +305,7 @@ void test_visit() constexpr bool operator()(const int&) { return true; } constexpr bool operator()(const nonliteral&) { return false; } }; - static_assert(visit(Visitor(), variant(0)), ""); + static_assert(visit(Visitor(), variant(0))); } // PR libstdc++/79513 { @@ -318,17 +318,17 @@ void test_visit() void test_constexpr() { constexpr variant a; - static_assert(holds_alternative(a), ""); + static_assert(holds_alternative(a)); constexpr variant b(in_place_index<0>, int{}); - static_assert(holds_alternative(b), ""); + static_assert(holds_alternative(b)); constexpr variant c(in_place_type, int{}); - static_assert(holds_alternative(c), ""); + static_assert(holds_alternative(c)); constexpr variant d(in_place_index<1>, char{}); - static_assert(holds_alternative(d), ""); + static_assert(holds_alternative(d)); constexpr variant e(in_place_type, char{}); - static_assert(holds_alternative(e), ""); + static_assert(holds_alternative(e)); constexpr variant f(char{}); - static_assert(holds_alternative(f), ""); + static_assert(holds_alternative(f)); { struct literal { @@ -342,51 +342,51 @@ void test_constexpr() { constexpr variant a(42); - static_assert(get<0>(a) == 42, ""); + static_assert(get<0>(a) == 42); } { constexpr variant a(42); - static_assert(get<0>(a) == 42, ""); + static_assert(get<0>(a) == 42); } { constexpr variant a(42); - static_assert(get<1>(a) == 42, ""); + static_assert(get<1>(a) == 42); } { constexpr variant a(42); - static_assert(get(a) == 42, ""); + static_assert(get(a) == 42); } { constexpr variant a(42); - static_assert(get(a) == 42, ""); + static_assert(get(a) == 42); } { constexpr variant a(42); - static_assert(get(a) == 42, ""); + static_assert(get(a) == 42); } { constexpr variant a(42); - static_assert(get<0>(std::move(a)) == 42, ""); + static_assert(get<0>(std::move(a)) == 42); } { constexpr variant a(42); - static_assert(get<0>(std::move(a)) == 42, ""); + static_assert(get<0>(std::move(a)) == 42); } { constexpr variant a(42); - static_assert(get<1>(std::move(a)) == 42, ""); + static_assert(get<1>(std::move(a)) == 42); } { constexpr variant a(42); - static_assert(get(std::move(a)) == 42, ""); + static_assert(get(std::move(a)) == 42); } { constexpr variant a(42); - static_assert(get(std::move(a)) == 42, ""); + static_assert(get(std::move(a)) == 42); } { constexpr variant a(42); - static_assert(get(std::move(a)) == 42, ""); + static_assert(get(std::move(a)) == 42); } } @@ -434,12 +434,12 @@ void test_adl() void test_variant_alternative() { - static_assert(is_same_v>, int>, ""); - static_assert(is_same_v>, string>, ""); + static_assert(is_same_v>, int>); + static_assert(is_same_v>, string>); - static_assert(is_same_v>, const int>, ""); - static_assert(is_same_v>, volatile int>, ""); - static_assert(is_same_v>, const volatile int>, ""); + static_assert(is_same_v>, const int>); + static_assert(is_same_v>, volatile int>); + static_assert(is_same_v>, const volatile int>); } template @@ -460,11 +460,11 @@ template void test_emplace() { - static_assert(has_type_emplace, int>(0), ""); - static_assert(!has_type_emplace, int>(0), ""); - static_assert(has_index_emplace, 0>(0), ""); - static_assert(!has_type_emplace, AllDeleted>(0), ""); - static_assert(!has_index_emplace, 0>(0), ""); + static_assert(has_type_emplace, int>(0)); + static_assert(!has_type_emplace, int>(0)); + static_assert(has_index_emplace, 0>(0)); + static_assert(!has_type_emplace, AllDeleted>(0)); + static_assert(!has_index_emplace, 0>(0)); } void test_triviality() @@ -479,10 +479,10 @@ void test_triviality() A& operator=(const A&) CA; \ A& operator=(A&&) MA; \ }; \ - static_assert(CC_VAL == is_trivially_copy_constructible_v>, ""); \ - static_assert(MC_VAL == is_trivially_move_constructible_v>, ""); \ - static_assert(CA_VAL == is_trivially_copy_assignable_v>, ""); \ - static_assert(MA_VAL == is_trivially_move_assignable_v>, ""); \ + static_assert(CC_VAL == is_trivially_copy_constructible_v>); \ + static_assert(MC_VAL == is_trivially_move_constructible_v>); \ + static_assert(CA_VAL == is_trivially_copy_assignable_v>); \ + static_assert(MA_VAL == is_trivially_move_assignable_v>); \ } TEST_TEMPLATE(=default, =default, =default, =default, =default, true, true, true, true) TEST_TEMPLATE(=default, =default, =default, =default, , true, true, true, false) @@ -527,10 +527,10 @@ void test_triviality() A& operator=(const A&) CA; \ A& operator=(A&&) MA; \ }; \ - static_assert(!is_trivially_copy_constructible_v>, ""); \ - static_assert(!is_trivially_move_constructible_v>, ""); \ - static_assert(!is_trivially_copy_assignable_v>, ""); \ - static_assert(!is_trivially_move_assignable_v>, ""); \ + static_assert(!is_trivially_copy_constructible_v>); \ + static_assert(!is_trivially_move_constructible_v>); \ + static_assert(!is_trivially_copy_assignable_v>); \ + static_assert(!is_trivially_move_assignable_v>); \ } TEST_TEMPLATE(=default, =default, =default, =default) TEST_TEMPLATE(=default, =default, =default, ) @@ -550,8 +550,8 @@ void test_triviality() TEST_TEMPLATE( , , , ) #undef TEST_TEMPLATE - static_assert(is_trivially_copy_constructible_v>, ""); - static_assert(is_trivially_move_constructible_v>, ""); - static_assert(is_trivially_copy_assignable_v>, ""); - static_assert(is_trivially_move_assignable_v>, ""); + static_assert(is_trivially_copy_constructible_v>); + static_assert(is_trivially_move_constructible_v>); + static_assert(is_trivially_copy_assignable_v>); + static_assert(is_trivially_move_assignable_v>); } From patchwork Wed Apr 17 16:12:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1087040 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-499394-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.b="rAkeGzqY"; 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 44knLl3jwLz9s4V for ; Thu, 18 Apr 2019 02:12:15 +1000 (AEST) 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:references:mime-version:content-type :in-reply-to; q=dns; s=default; b=eJFlWdwFYzBtnMDIX8WXpdYEfYpiKw yAy4ribC7XoAa/tIF3QWvXDdRQ5lv7B10u5HotYTJPf3GhTWBOLfKy1GSro+JpfI sjJWH6L1gstOLGQREeI7tPLqLaVQgDelARDkdKgdpHHO3y2Mnk18zhRLPf5046Tc 2gAFHqsCMofqY= 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:references:mime-version:content-type :in-reply-to; s=default; bh=Y5mSEuekYpyNreIFGusilXstZQU=; b=rAke GzqYzI1YIhR/fw0U3Mlmaj4zFrp0agDNpHSRqcbO2S5MR3n72qYC3iV/OariaRuZ h0Kkg3nV+y9up0569ur0qY4rbvnDz0Pd7TlDhl9Zidsj4rxn/6IbGjh4a43zs9fi DheOdoMLjjz1CtucYZyytoEqEiGBSv0x7pZmUTM= Received: (qmail 23505 invoked by alias); 17 Apr 2019 16:12:07 -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 23468 invoked by uid 89); 17 Apr 2019 16:12:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=enhance, revealed, falls X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 17 Apr 2019 16:12:02 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 24C23308A102; Wed, 17 Apr 2019 16:12:01 +0000 (UTC) Received: from localhost (unknown [10.33.36.125]) by smtp.corp.redhat.com (Postfix) with ESMTP id C502560143; Wed, 17 Apr 2019 16:12:00 +0000 (UTC) Date: Wed, 17 Apr 2019 17:12:00 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 3/3] Fix condition for std::variant to be copy constructible Message-ID: <20190417161200.GY943@redhat.com> References: <20190417160743.GA31346@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190417160743.GA31346@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.11.3 (2019-02-01) The standard says the std::variant copy constructor is defined as deleted unless all alternative types are copy constructible, but we were making it also depend on move constructible. Fix the condition and enhance the tests to check the semantics with pathological copy-only types (i.e. supporting copying but having deleted moves). The enhanced tests revealed a regression in copy assignment for non-trivial alternative types, where the assignment would not be performed because the condition in the _Copy_assign_base visitor is false: is_same_v, remove_reference_t>. Tested powerpc64le-linux. I plan to commit all three of these patches later today, unless somebody sees a problem with them. commit a5a517df4933ffd0e6a08c42280c7d2ee0699904 Author: Jonathan Wakely Date: Wed Apr 17 16:17:25 2019 +0100 Fix condition for std::variant to be copy constructible The standard says the std::variant copy constructor is defined as deleted unless all alternative types are copy constructible, but we were making it also depend on move constructible. Fix the condition and enhance the tests to check the semantics with pathological copy-only types (i.e. supporting copying but having deleted moves). The enhanced tests revealed a regression in copy assignment for non-trivial alternative types, where the assignment would not be performed because the condition in the _Copy_assign_base visitor is false: is_same_v, remove_reference_t>. * include/std/variant (__detail::__variant::_Traits::_S_copy_assign): Do not depend on whether all alternative types are move constructible. (__detail::__variant::_Copy_assign_base::operator=): Remove cv-quals from the operand when deciding whether to perform the assignment. * testsuite/20_util/variant/compile.cc (DeletedMoves): Define type with deleted move constructor and deleted move assignment operator. (default_ctor, copy_ctor, move_ctor, copy_assign, move_assign): Check behaviour of variants with DeletedMoves as an alternative. * testsuite/20_util/variant/run.cc (DeletedMoves): Define same type. (move_ctor, move_assign): Check that moving a variant with a DeletedMoves alternative falls back to copying instead of moving. diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 22b0c3d5c22..e153363bbf3 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -279,7 +279,7 @@ namespace __variant static constexpr bool _S_move_ctor = (is_move_constructible_v<_Types> && ...); static constexpr bool _S_copy_assign = - _S_copy_ctor && _S_move_ctor + _S_copy_ctor && (is_copy_assignable_v<_Types> && ...); static constexpr bool _S_move_assign = _S_move_ctor @@ -613,7 +613,7 @@ namespace __variant __variant::__get<__rhs_index>(*this); if constexpr (is_same_v< remove_reference_t, - remove_reference_t>) + __remove_cvref_t>) __this_mem = __rhs_mem; } } diff --git a/libstdc++-v3/testsuite/20_util/variant/compile.cc b/libstdc++-v3/testsuite/20_util/variant/compile.cc index b67c98adf4a..5cc2a9460a9 100644 --- a/libstdc++-v3/testsuite/20_util/variant/compile.cc +++ b/libstdc++-v3/testsuite/20_util/variant/compile.cc @@ -63,6 +63,15 @@ struct MoveCtorOnly struct MoveCtorAndSwapOnly : MoveCtorOnly { }; void swap(MoveCtorAndSwapOnly&, MoveCtorAndSwapOnly&) { } +struct DeletedMoves +{ + DeletedMoves() = default; + DeletedMoves(const DeletedMoves&) = default; + DeletedMoves(DeletedMoves&&) = delete; + DeletedMoves& operator=(const DeletedMoves&) = default; + DeletedMoves& operator=(DeletedMoves&&) = delete; +}; + struct nonliteral { nonliteral() { } @@ -81,6 +90,7 @@ void default_ctor() static_assert(is_default_constructible_v>); static_assert(!is_default_constructible_v>); static_assert(is_default_constructible_v>); + static_assert(is_default_constructible_v>); static_assert(noexcept(variant())); static_assert(!noexcept(variant())); @@ -93,6 +103,7 @@ void copy_ctor() static_assert(!is_copy_constructible_v>); static_assert(is_trivially_copy_constructible_v>); static_assert(!is_trivially_copy_constructible_v>); + static_assert(is_trivially_copy_constructible_v>); { variant a; @@ -116,6 +127,7 @@ void move_ctor() { static_assert(is_move_constructible_v>); static_assert(!is_move_constructible_v>); + static_assert(is_move_constructible_v>); // uses copy ctor static_assert(is_trivially_move_constructible_v>); static_assert(!is_trivially_move_constructible_v>); static_assert(!noexcept(variant(declval>()))); @@ -157,6 +169,7 @@ void copy_assign() static_assert(!is_copy_assignable_v>); static_assert(is_trivially_copy_assignable_v>); static_assert(!is_trivially_copy_assignable_v>); + static_assert(is_trivially_copy_assignable_v>); { variant a; static_assert(!noexcept(a = a)); @@ -171,6 +184,7 @@ void move_assign() { static_assert(is_move_assignable_v>); static_assert(!is_move_assignable_v>); + static_assert(is_move_assignable_v>); // uses copy assignment static_assert(is_trivially_move_assignable_v>); static_assert(!is_trivially_move_assignable_v>); { diff --git a/libstdc++-v3/testsuite/20_util/variant/run.cc b/libstdc++-v3/testsuite/20_util/variant/run.cc index 3ca375d374e..c0f48432ca1 100644 --- a/libstdc++-v3/testsuite/20_util/variant/run.cc +++ b/libstdc++-v3/testsuite/20_util/variant/run.cc @@ -57,6 +57,15 @@ struct AlwaysThrow bool operator>(const AlwaysThrow&) const { VERIFY(false); } }; +struct DeletedMoves +{ + DeletedMoves() = default; + DeletedMoves(const DeletedMoves&) = default; + DeletedMoves(DeletedMoves&&) = delete; + DeletedMoves& operator=(const DeletedMoves&) = default; + DeletedMoves& operator=(DeletedMoves&&) = delete; +}; + void default_ctor() { variant v; @@ -80,6 +89,12 @@ void move_ctor() VERIFY(holds_alternative(u)); VERIFY(get(u) == "a"); VERIFY(holds_alternative(v)); + + variant, DeletedMoves> d{std::in_place_index<0>, {1, 2, 3, 4}}; + // DeletedMoves is not move constructible, so this uses copy ctor: + variant, DeletedMoves> e(std::move(d)); + VERIFY(std::get<0>(d).size() == 4); + VERIFY(std::get<0>(e).size() == 4); } void arbitrary_ctor() @@ -137,6 +152,13 @@ void move_assign() VERIFY(holds_alternative(u)); VERIFY(get(u) == "a"); VERIFY(holds_alternative(v)); + + variant, DeletedMoves> d{std::in_place_index<0>, {1, 2, 3, 4}}; + variant, DeletedMoves> e; + // DeletedMoves is not move assignable, so this uses copy assignment: + e = std::move(d); + VERIFY(std::get<0>(d).size() == 4); + VERIFY(std::get<0>(e).size() == 4); } void arbitrary_assign()