From patchwork Wed Mar 18 23:21:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1257858 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=xt6+XTxX; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48jQz15wXsz9sPF for ; Thu, 19 Mar 2020 10:21:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5C40D395ACCB; Wed, 18 Mar 2020 23:21:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C40D395ACCB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584573689; bh=t+Rc2VtgnzPclJ23ezDymEx7eFiqOyANOyM+F70FtAc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=xt6+XTxXwH88NEryKLD9GXasA3du0rvspQy4MlyGesen/x9TStdp9P8oRDxHP19un SCW0r3PI34KmONTahBi5uoY1VAmfJ9alqJ9MYunkENSC9ufIhmWVkf+pseEzbViley U6DI2ufi8gJDNLsNM2GAX1/K4UWhNaimeFExAtZE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by sourceware.org (Postfix) with ESMTP id 49410394B019 for ; Wed, 18 Mar 2020 23:21:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 49410394B019 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-131-tQx25FLGNhClqgkRlfx2Xw-1; Wed, 18 Mar 2020 19:21:23 -0400 X-MC-Unique: tQx25FLGNhClqgkRlfx2Xw-1 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 E3A44107ACC7; Wed, 18 Mar 2020 23:21:22 +0000 (UTC) Received: from localhost (unknown [10.33.36.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75BB95C1D8; Wed, 18 Mar 2020 23:21:22 +0000 (UTC) Date: Wed, 18 Mar 2020 23:21:21 +0000 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix is_trivially_constructible (PR 94033) Message-ID: <20200318232121.GA4027290@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-25.2 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This attempts to make is_nothrow_constructible more robust (and efficient to compile) by not depending on is_constructible. Instead the __is_constructible intrinsic is used directly. The helper class __is_nt_constructible_impl which checks whether the construction is non-throwing now takes a bool template parameter that is substituted by the result of the instrinsic. This fixes the reported bug by not using the already-instantiated (and incorrect) value of std::is_constructible. I don't think it really fixes the problem in general, because std::is_nothrow_constructible itself could already have been instantiated in a context where it gives the wrong result. A proper fix needs to be done in the compiler. PR libstdc++/94033 * include/std/type_traits (__is_nt_default_constructible_atom): Remove. (__is_nt_default_constructible_impl): Remove. (__is_nothrow_default_constructible_impl): Remove. (__is_nt_constructible_impl): Add bool template parameter. Adjust partial specializations. (__is_nothrow_constructible_impl): Replace class template with alias template. (is_nothrow_default_constructible): Derive from alias template __is_nothrow_constructible_impl instead of __is_nothrow_default_constructible_impl. * testsuite/20_util/is_nothrow_constructible/94003.cc: New test. Tested powerpc64le-linux, committed to master. commit b3341826531e80e02f194460b4fbe1b0541c0463 Author: Jonathan Wakely Date: Wed Mar 18 23:19:12 2020 +0000 libstdc++: Fix is_trivially_constructible (PR 94033) This attempts to make is_nothrow_constructible more robust (and efficient to compile) by not depending on is_constructible. Instead the __is_constructible intrinsic is used directly. The helper class __is_nt_constructible_impl which checks whether the construction is non-throwing now takes a bool template parameter that is substituted by the result of the instrinsic. This fixes the reported bug by not using the already-instantiated (and incorrect) value of std::is_constructible. I don't think it really fixes the problem in general, because std::is_nothrow_constructible itself could already have been instantiated in a context where it gives the wrong result. A proper fix needs to be done in the compiler. PR libstdc++/94033 * include/std/type_traits (__is_nt_default_constructible_atom): Remove. (__is_nt_default_constructible_impl): Remove. (__is_nothrow_default_constructible_impl): Remove. (__is_nt_constructible_impl): Add bool template parameter. Adjust partial specializations. (__is_nothrow_constructible_impl): Replace class template with alias template. (is_nothrow_default_constructible): Derive from alias template __is_nothrow_constructible_impl instead of __is_nothrow_default_constructible_impl. * testsuite/20_util/is_nothrow_constructible/94003.cc: New test. diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 14aa2b37a4f..68abf148a38 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -961,61 +961,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION "template argument must be a complete class or an unbounded array"); }; - template - struct __is_nt_default_constructible_atom - : public integral_constant + template + struct __is_nt_constructible_impl + : public false_type { }; - template::value> - struct __is_nt_default_constructible_impl; - - template - struct __is_nt_default_constructible_impl<_Tp, true> - : public __and_<__is_array_known_bounds<_Tp>, - __is_nt_default_constructible_atom::type>> - { }; - - template - struct __is_nt_default_constructible_impl<_Tp, false> - : public __is_nt_default_constructible_atom<_Tp> - { }; - - template - using __is_nothrow_default_constructible_impl - = __and_<__is_constructible_impl<_Tp>, - __is_nt_default_constructible_impl<_Tp>>; - - /// is_nothrow_default_constructible - template - struct is_nothrow_default_constructible - : public __is_nothrow_default_constructible_impl<_Tp>::type - { - static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}), - "template argument must be a complete class or an unbounded array"); - }; - template - struct __is_nt_constructible_impl - : public integral_constant()...))> + struct __is_nt_constructible_impl + : public __bool_constant()...))> { }; template - struct __is_nt_constructible_impl<_Tp, _Arg> - : public integral_constant(declval<_Arg>()))> + struct __is_nt_constructible_impl + : public __bool_constant(std::declval<_Arg>()))> { }; template - struct __is_nt_constructible_impl<_Tp> - : public __is_nothrow_default_constructible_impl<_Tp> + struct __is_nt_constructible_impl + : public __bool_constant + { }; + + template + struct __is_nt_constructible_impl + : public __bool_constant::type())> { }; template - struct __is_nothrow_constructible_impl - : public __and_<__is_constructible_impl<_Tp, _Args...>, - __is_nt_constructible_impl<_Tp, _Args...>> - { }; + using __is_nothrow_constructible_impl + = __is_nt_constructible_impl<__is_constructible(_Tp, _Args...), + _Tp, _Args...>; /// is_nothrow_constructible template @@ -1026,6 +1000,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION "template argument must be a complete class or an unbounded array"); }; + /// is_nothrow_default_constructible + template + struct is_nothrow_default_constructible + : public __is_nothrow_constructible_impl<_Tp>::type + { + static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}), + "template argument must be a complete class or an unbounded array"); + }; + + template::value> struct __is_nothrow_copy_constructible_impl; diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/94003.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/94003.cc new file mode 100644 index 00000000000..392a0878ba5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_constructible/94003.cc @@ -0,0 +1,46 @@ +// 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++17" } +// { dg-do compile { target c++17 } } + +#include +#include + +template struct abc {}; + +template + +struct future : public abc>> {}; + +class mutation { + mutation(); + friend class std::optional; +}; + +using mutation_opt = std::optional; + +future foo(); + +template future consume_partitions() { + return foo(); +} + +future bar() { return consume_partitions(); } + +future zed(); +future apply_counter_update() { return zed(); }