From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id DAEB13858D20; Sun, 7 Jan 2024 00:59:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAEB13858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704589194; bh=ZJFcnRI9vhFQqqX9IO/xyd6nigKgy6Vq5VyRu/a+X0E=; h=From:To:Subject:Date:From; b=LUJtgg0eGFU+zWtFEYge1Ub2Qy5p/QEhC6+oosgYTJ2j8TqPppfAf2IZftnfCkCjO +tDOBaXzw0EfgNIjQ4nWAjGaUzD72WzQv0bQmOaUn42GWGRZ2G3tuYxlzXCUuGX42z uMbKcC3xwkgkoe/IFlYea4OuJ56hL08Lj+DBnANk= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-6973] libstdc++: Optimize std::is_trivially_destructible_v X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: b368d79998003c2e5657a91055cb27991988b44b X-Git-Newrev: 7af436ada243bbb6ae601c85bd47ea908c71fb41 Message-Id: <20240107005954.DAEB13858D20@sourceware.org> Date: Sun, 7 Jan 2024 00:59:54 +0000 (GMT) List-Id: https://gcc.gnu.org/g:7af436ada243bbb6ae601c85bd47ea908c71fb41 commit r14-6973-g7af436ada243bbb6ae601c85bd47ea908c71fb41 Author: Jonathan Wakely Date: Wed Nov 22 15:09:24 2023 +0000 libstdc++: Optimize std::is_trivially_destructible_v This reduces the overhead of using std::is_trivially_destructible_v and as a result fixes some recent regressions seen with a non-default GLIBCXX_TESTSUITE_STDS env var: FAIL: 20_util/variant/87619.cc -std=gnu++20 (test for excess errors) FAIL: 20_util/variant/87619.cc -std=gnu++23 (test for excess errors) FAIL: 20_util/variant/87619.cc -std=gnu++26 (test for excess errors) libstdc++-v3/ChangeLog: * include/std/type_traits (is_trivially_destructible_v): Use built-in directly when concepts are supported. * testsuite/20_util/is_trivially_destructible/value_v.cc: New test. Diff: --- libstdc++-v3/include/std/type_traits | 19 ++++++++++ .../20_util/is_trivially_destructible/value_v.cc | 40 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 3b1b419bbbb..1cec0822b73 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3410,9 +3410,28 @@ template inline constexpr bool is_trivially_move_assignable_v = __is_trivially_assignable(__add_lval_ref_t<_Tp>, __add_rval_ref_t<_Tp>); + +#if __cpp_concepts +template + inline constexpr bool is_trivially_destructible_v = false; + +template + requires (!is_reference_v<_Tp>) && requires (_Tp& __t) { __t.~_Tp(); } + inline constexpr bool is_trivially_destructible_v<_Tp> + = __has_trivial_destructor(_Tp); +template + inline constexpr bool is_trivially_destructible_v<_Tp&> = true; +template + inline constexpr bool is_trivially_destructible_v<_Tp&&> = true; +template + inline constexpr bool is_trivially_destructible_v<_Tp[_Nm]> + = is_trivially_destructible_v<_Tp>; +#else template inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<_Tp>::value; +#endif + template inline constexpr bool is_nothrow_constructible_v = __is_nothrow_constructible(_Tp, _Args...); diff --git a/libstdc++-v3/testsuite/20_util/is_trivially_destructible/value_v.cc b/libstdc++-v3/testsuite/20_util/is_trivially_destructible/value_v.cc new file mode 100644 index 00000000000..7db098a2c4d --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/is_trivially_destructible/value_v.cc @@ -0,0 +1,40 @@ +// { dg-do compile { target c++17 } } +#include +#include + +template +constexpr void test_cv() +{ + static_assert(std::is_trivially_destructible_v + == std::is_trivially_destructible_v); + static_assert(std::is_trivially_destructible_v + == std::is_trivially_destructible_v); + static_assert(std::is_trivially_destructible_v + == std::is_trivially_destructible_v); +} + +template +void test() +{ + static_assert(std::is_trivially_destructible_v == Expected); + test_cv(); +} + +void test01() +{ + using namespace __gnu_test; + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); +}