From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B3CEA3858C62 for ; Thu, 14 Dec 2023 01:09:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B3CEA3858C62 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B3CEA3858C62 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702516149; cv=none; b=Q9yOv4pClAhIXr1Bzt/wY8I/uSTBZ6NHAteWa3yjY+RcC9o5atFJCI4mNB31fpWi/2ge/uneVU+FuoDuPbDxj1Uw+T+Nyog6Gb+WMCLcD0wC35eoqEr5MIq1WHqdXkf5cDnBrqquDruwqMd0VGjNbXz6azNI2SaGsUZdEjtNSiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702516149; c=relaxed/simple; bh=cRgtR88FOHMtiSwD3WvUIuLJdk29B63gaAjEvK3XKOY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gwi4vTIozO9xjR6TmPEE/yTlBIoJeh4XsJYmeYpz+g4lTS5XyOYMRrWmKA6sRgY0TMsKF5h8JEll2VH/Wi5okFOxWelxcywgigL8dWScoLv9ERCVo+J+a0myRFcXbpt2iK7ZFW00AFs7itApdgrrW2JhMi/InDc8wXNzovznkKg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702516147; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xZ8A26v3YE2Em+Va5+EiS+BQs/K9n7mIpR92Zkv8/SA=; b=ZaWb4DShzHfX4VzyPfQfqMsp/aVdLsK/NtZ+2unAy23o6e7bDrG4XhN8Unn2afycT8vBCa G7sIK5Pm51PBQVmflx8KAhR533fpBU+OFeKI/GbWNXV30iCw0qY7gYF3p8cu2V1i/dKoXY znZiyEv9kHNTY+IdByBZfVquXz2k6bQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-228-p4B-oytdPiuWgmzS9-tSfA-1; Wed, 13 Dec 2023 20:09:05 -0500 X-MC-Unique: p4B-oytdPiuWgmzS9-tSfA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 72E483C2AF67; Thu, 14 Dec 2023 01:09:05 +0000 (UTC) Received: from localhost (unknown [10.42.28.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E0CE3C25; Thu, 14 Dec 2023 01:09:05 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Optimize std::is_trivially_destructible_v Date: Thu, 14 Dec 2023 01:07:32 +0000 Message-ID: <20231214010904.1724915-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested x86_64-linux. Does this look right? Can we do it faster, or simplify it? -- >8 -- 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. --- libstdc++-v3/include/std/type_traits | 19 +++++++++ .../is_trivially_destructible/value_v.cc | 40 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 libstdc++-v3/testsuite/20_util/is_trivially_destructible/value_v.cc diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 677cd934b94..a0821347676 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3300,9 +3300,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(); +} -- 2.43.0