From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 4319338582BE; Thu, 7 Jul 2022 23:31:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4319338582BE 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 r11-10114] libstdc++: Define std::hash (LWG 3657) X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: c3cb4eef112d81c7682faa6e4e2153532520be44 X-Git-Newrev: c8af57eefe1ac4c1f230979ee0714852c6f77c17 Message-Id: <20220707233153.4319338582BE@sourceware.org> Date: Thu, 7 Jul 2022 23:31:53 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jul 2022 23:31:53 -0000 https://gcc.gnu.org/g:c8af57eefe1ac4c1f230979ee0714852c6f77c17 commit r11-10114-gc8af57eefe1ac4c1f230979ee0714852c6f77c17 Author: Jonathan Wakely Date: Mon Apr 25 18:21:57 2022 +0100 libstdc++: Define std::hash (LWG 3657) This DR was approved at the February 2022 plenary. libstdc++-v3/ChangeLog: * include/bits/fs_path.h (hash): Define. * testsuite/27_io/filesystem/path/nonmember/hash_value.cc: Check std::hash specialization. (cherry picked from commit e3c5e8360b4e4799e1e2daf74282629248690f23) Diff: --- libstdc++-v3/include/bits/fs_path.h | 10 ++++++++++ .../testsuite/27_io/filesystem/path/nonmember/hash_value.cc | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h index a1f780a9c9b..79085c0c1bd 100644 --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -1361,6 +1361,16 @@ extern template class __shared_ptr; /// @endcond +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// 3657. std::hash is not enabled +template<> + struct hash + { + size_t + operator()(const filesystem::path& __p) const noexcept + { return filesystem::hash_value(__p); } + }; + _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/hash_value.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/hash_value.cc index 7b7c912a6df..be15b314149 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/hash_value.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/hash_value.cc @@ -42,9 +42,19 @@ test02() } } +void +test03() +{ + std::hash h; + // LWG 3657. std::hash is not enabled + for (const path p : __gnu_test::test_paths) + VERIFY( h(p) == hash_value(p) ); +} + int main() { test01(); test02(); + test03(); }