From: Jonathan Wakely Date: Wed, 18 Mar 2020 23:19:12 +0000 (+0000) Subject: libstdc++: Fix is_trivially_constructible (PR 94033) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b3341826531e80e02f194460b4fbe1b0541c0463;p=gcc.git 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/ChangeLog b/libstdc++-v3/ChangeLog index a9cd2599243..e58aef733ae 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,18 @@ 2020-03-18 Jonathan Wakely + 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. + * include/std/stop_token (stop_token::_Stop_state_ref): Define comparison operators explicitly if the compiler won't synthesize them. 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,62 +961,36 @@ _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::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 + struct __is_nt_constructible_impl + : public false_type { }; - 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_nothrow_constructible_impl - : public __and_<__is_constructible_impl<_Tp, _Args...>, - __is_nt_constructible_impl<_Tp, _Args...>> + template + struct __is_nt_constructible_impl + : public __bool_constant::type())> { }; + template + using __is_nothrow_constructible_impl + = __is_nt_constructible_impl<__is_constructible(_Tp, _Args...), + _Tp, _Args...>; + /// is_nothrow_constructible template struct is_nothrow_constructible @@ -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(); }