{"id":2226257,"url":"http://patchwork.ozlabs.org/api/covers/2226257/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/cover/bmm.hhub9plyek.gcc.gcc-TEST.redi.16.1.0@forge-stage.sourceware.org/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<bmm.hhub9plyek.gcc.gcc-TEST.redi.16.1.0@forge-stage.sourceware.org>","list_archive_url":null,"date":"2026-04-22T10:26:25","name":"[v1,0/1] libstdc++: Refactor std::hash specializations","submitter":{"id":93210,"url":"http://patchwork.ozlabs.org/api/people/93210/?format=json","name":"Jonathan Wakely via Sourceware Forge","email":"forge-bot+redi@forge-stage.sourceware.org"},"mbox":"http://patchwork.ozlabs.org/project/gcc/cover/bmm.hhub9plyek.gcc.gcc-TEST.redi.16.1.0@forge-stage.sourceware.org/mbox/","series":[{"id":500974,"url":"http://patchwork.ozlabs.org/api/series/500974/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=500974","date":"2026-04-22T10:26:26","name":"libstdc++: Refactor std::hash specializations","version":1,"mbox":"http://patchwork.ozlabs.org/series/500974/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/covers/2226257/comments/","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org; dmarc=none (p=none dis=none)\n header.from=forge-stage.sourceware.org","sourceware.org;\n spf=pass smtp.mailfrom=forge-stage.sourceware.org","server2.sourceware.org;\n arc=none smtp.remote-ip=38.145.34.39"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g0wwR0rS2z1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 20:49:59 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id D0C1B4335881\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 10:49:56 +0000 (GMT)","from forge-stage.sourceware.org (vm08.sourceware.org [38.145.34.39])\n by sourceware.org (Postfix) with ESMTPS id 3A5AE4B920DB\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 10:27:19 +0000 (GMT)","from forge-stage.sourceware.org (localhost [IPv6:::1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256)\n (No client certificate requested)\n by forge-stage.sourceware.org (Postfix) with ESMTPS id 10CC6405A9\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 10:27:19 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org D0C1B4335881","OpenDKIM Filter v2.11.0 sourceware.org 3A5AE4B920DB"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 3A5AE4B920DB","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 3A5AE4B920DB","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776853639; cv=none;\n b=rSEEo5UbkH8tAWSusipzysR6895Qcrdq/LTGhSkKQL/c5ejqnJZIjPqt2he7OKucNWUCIXKtgzgu1m5BcfK+dpuIWfAZ1IyLzrm6VO6OxdGpStRJpm5iLE9+bRQQSn1zY5hRP2ydM9PVW/yIyWO4GKhQc36OgAo/ORUrPPhW3ZU=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776853639; c=relaxed/simple;\n bh=JMIRLLH7kteBua8F1eMeW1JUQjADsksD1ua7YjLAxcQ=;\n h=From:Date:Subject:To:Message-ID;\n b=k0p//zXzlU/sOsNM6tBCQyrV52M0bD3qLrMDzdaLqiYYSJPTwKYjBNyy8TEnhhJ9HL8sggnO2t3tJt6aEve1CAySbGBUVcxmxTRLRBHeaMCxz9/DYAEuyNgSn6aNRv1e8b9eoVB+XNfWNxiFqKLkzTmwEh3J7PiB2TTkkETXxJc=","ARC-Authentication-Results":"i=1; server2.sourceware.org","From":"Jonathan Wakely via Sourceware Forge\n <forge-bot+redi@forge-stage.sourceware.org>","Date":"Wed, 22 Apr 2026 10:26:25 +0000","Subject":"[PATCH v1 0/1] libstdc++: Refactor std::hash specializations","To":"gcc-patches mailing list <gcc-patches@gcc.gnu.org>","Message-ID":"\n <bmm.hhub9plyek.gcc.gcc-TEST.redi.16.1.0@forge-stage.sourceware.org>","X-Mailer":"batrachomyomachia","X-Pull-Request-Organization":"gcc","X-Pull-Request-Repository":"gcc-TEST","X-Pull-Request":"https://forge.sourceware.org/gcc/gcc-TEST/pulls/16","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Reply-To":"gcc-patches mailing list <gcc-patches@gcc.gnu.org>, redi@gcc.gnu.org","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"Hi gcc-patches mailing list,\nJonathan Wakely via Sourceware Forge <forge-bot+redi@forge-stage.sourceware.org> has requested that the following forgejo pull request\nbe published on the mailing list.\n\nCreated on: 2024-11-06 15:46:39+00:00\nLatest update: 2025-12-16 09:30:48+00:00\nChanges: 0 changed files, 0 additions, 0 deletions\nHead revision: redi/gcc ref refs/pull/16/head commit 34be1a8927df3aad5db13394a813c60dd83c4e14\nBase revision: gcc/gcc-TEST ref trunk commit 85736ba8e1fc4a5003f958dd268a155e379e059f r15-4983-g85736ba8e1fc4a\nMerge base: 85736ba8e1fc4a5003f958dd268a155e379e059f\nFull diff url: https://forge.sourceware.org/gcc/gcc-TEST/pulls/16.diff\nDiscussion:  https://forge.sourceware.org/gcc/gcc-TEST/pulls/16\nRequested Reviewers:\n\nThis attempts to simplify and clean up our std::hash code. The primary\nbenefit is improved diagnostics for users when they do something wrong\ninvolving std::hash or unordered containers. An additional benefit is\nthat for the unstable ABI (--enable-symvers=gnu-versioned-namespace) we\ncan reduce the memory footprint of several std::hash specializations.\n\nIn the current design, __hash_enum is a base class of the std::hash\nprimary template, but the partial specialization of __hash_enum for\nnon-enum types is disabled.  This means that if a user forgets to\nspecialize std::hash for their class type (or forgets to use a custom\nhash function for unordered containers) they get error messages about\nstd::__hash_enum not being constructible.  This is confusing when there\nis no enum type involved: why should users care about __hash_enum not\nbeing constructible if they're not trying to hash enums?\n\nThis change makes the std::hash primary template only derive from\n__hash_enum when the template argument type is an enum. Otherwise, it\nderives directly from a new class template, __hash_not_enabled. This new\nclass template defines the deleted members that cause a given std::hash\nspecialization to be a disabled specialization (as per P0513R0). Now\nwhen users try to use a disabled specialization, they get more\ndescriptive errors that mention __hash_not_enabled instead of\n__hash_enum.\n\nAdditionally, adjust __hash_base to remove the deprecated result_type\nand argument_type typedefs for C++20 and later.\n\nIn the current code we use a __poison_hash base class in the std::hash\nspecializations for std::unique_ptr, std::optional, and std::variant.\nThe primary template of __poison_hash has deleted special members, which\nis used to conditionally disable the derived std::hash specialization.\nThis can also result in confusing diagnostics, because seeing \"poison\"\nin an enabled specialization is misleading. Only some uses of\n__poison_hash actually \"poison\" anything, i.e. cause a specialization to\nbe disabled. In other cases it's just an empty base class that does\nnothing.\n\nThis change removes __poison_hash and changes the std::hash\nspecializations that were using it to conditionally derive from\n__hash_not_enabled instead. When the std::hash specialization is\nenabled, there is no more __poison_hash base class. However, to preserve\nthe ABI properties of those std::hash specializations, we need to\nreplace __poison_hash with some other empty base class. This is needed\nbecause in the current code std::hash<std::variant<int, const int>> has\ntwo __poison_hash<int> base classes, which must have unique addresses,\nso sizeof(std::hash<std::variant<int, const int>>) == 2. To preserve\nthis unfortunate property, a new __hash_empty_base class is used as a\nbase class to re-introduce du0plicate base classes that increase the\nclass size. For the unstable ABI we don't use __hash_empty_base so the\nstd::hash<std::variant<T...>> specializations are always size 1, and\nthe class hierarchy is much simpler so will compile faster.\n\nAdditionally, remove the result_type and argument_type typedefs from all\ndisabled specializations of std::hash for std::unique_ptr,\nstd::optional, and std::variant. Those typedefs are useless for disabled\nspecializations, and although the standard doesn't say they must *not*\nbe present for disabled specializations, it certainly only requires them\nfor enabled specializations. Finally, for C++20 the typedefs are also\nremoved from enabled specializations of std::hash for std::unique_ptr,\nstd::optional, and std::variant.\n\n```\nlibstdc++-v3/ChangeLog:\n\n\t* doc/xml/manual/evolution.xml: Document removal of nested types\n\tfrom std::hash specializations.\n\t* doc/html/manual/api.html: Regenerate.\n\t* include/bits/functional_hash.h (__hash_base): Remove\n\tdeprecated nested types for C++20.\n\t(__hash_empty_base): Define new class template.\n\t(__is_hash_enabled_for): Define new variable template.\n\t(__poison_hash): Remove.\n\t(__hash_not_enabled): Define new class template.\n\t(__hash_enum): Remove partial specialization for non-enums.\n\t(hash): Derive from __hash_not_enabled for non-enums, instead of\n\t__hash_enum.\n\t* include/bits/unique_ptr.h (__uniq_ptr_hash): Derive from\n\t__hash_base. Conditionally derive from __hash_empty_base.\n\t(__uniq_ptr_hash<>): Remove disabled specialization.\n\t(hash): Do not derive from __hash_base unconditionally.\n\tConditionally derive from either __uniq_ptr_hash or\n\t__hash_not_enabled.\n\t* include/std/optional (__optional_hash_call_base): Remove.\n\t(__optional_hash): Define new class template.\n\t(hash): Derive from either\n\t(hash): Conditionally derive from either __optional_hash or\n\t__hash_not_enabled. Remove nested typedefs.\n\t* include/std/variant (_Base_dedup): Replace __poison_hash with\n\t__hash_empty_base.\n\t(__variant_hash_call_base_impl): Remove.\n\t(__variant_hash): Define new class template.\n\t(hash): Conditionally derive from either __variant_hash or\n\t__hash_not_enabled. Remove nested typedefs.\n\t* testsuite/20_util/optional/hash.cc: Check whether nested types\n\tare present.\n\t* testsuite/20_util/variant/hash.cc: Likewise.\n\t* testsuite/20_util/optional/hash_abi.cc: New test.\n\t* testsuite/20_util/unique_ptr/hash/abi.cc: New test.\n\t* testsuite/20_util/unique_ptr/hash/types.cc: New test.\n\t* testsuite/20_util/variant/hash_abi.cc: New test.\n```\n\n\nChanged files:\n- A: libstdc++-v3/testsuite/20_util/optional/hash_abi.cc\n- A: libstdc++-v3/testsuite/20_util/unique_ptr/hash/abi.cc\n- A: libstdc++-v3/testsuite/20_util/unique_ptr/hash/types.cc\n- A: libstdc++-v3/testsuite/20_util/variant/hash_abi.cc\n- M: libstdc++-v3/doc/html/manual/api.html\n- M: libstdc++-v3/doc/xml/manual/evolution.xml\n- M: libstdc++-v3/include/bits/functional_hash.h\n- M: libstdc++-v3/include/bits/unique_ptr.h\n- M: libstdc++-v3/include/std/optional\n- M: libstdc++-v3/include/std/variant\n- M: libstdc++-v3/testsuite/20_util/optional/hash.cc\n- M: libstdc++-v3/testsuite/20_util/variant/hash.cc\n\n\nJonathan Wakely (1):\n  libstdc++: Refactor std::hash specializations\n\n libstdc++-v3/doc/html/manual/api.html         |  3 +\n libstdc++-v3/doc/xml/manual/evolution.xml     |  5 ++\n libstdc++-v3/include/bits/functional_hash.h   | 47 +++++++-------\n libstdc++-v3/include/bits/unique_ptr.h        | 18 +++---\n libstdc++-v3/include/std/optional             | 26 ++++----\n libstdc++-v3/include/std/variant              | 41 ++++++------\n .../testsuite/20_util/optional/hash.cc        | 33 ++++++++++\n .../testsuite/20_util/optional/hash_abi.cc    | 35 ++++++++++\n .../testsuite/20_util/unique_ptr/hash/abi.cc  | 64 +++++++++++++++++++\n .../20_util/unique_ptr/hash/types.cc          | 53 +++++++++++++++\n .../testsuite/20_util/variant/hash.cc         | 34 ++++++++++\n .../testsuite/20_util/variant/hash_abi.cc     | 48 ++++++++++++++\n 12 files changed, 344 insertions(+), 63 deletions(-)\n create mode 100644 libstdc++-v3/testsuite/20_util/optional/hash_abi.cc\n create mode 100644 libstdc++-v3/testsuite/20_util/unique_ptr/hash/abi.cc\n create mode 100644 libstdc++-v3/testsuite/20_util/unique_ptr/hash/types.cc\n create mode 100644 libstdc++-v3/testsuite/20_util/variant/hash_abi.cc"}