From patchwork Wed Apr 8 13:59:08 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Kaminski X-Patchwork-Id: 132813 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 79B2A4BA2E36 for ; Wed, 8 Apr 2026 14:02:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79B2A4BA2E36 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=g/ePBHdJ X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 9C5244BA2E17 for ; Wed, 8 Apr 2026 13:59:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C5244BA2E17 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 9C5244BA2E17 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=1775656784; cv=none; b=dc8tKMZcDRtYIXj8Yxp3GAGpNZkRHtoOQ1or5kWWqT6lU+z8tQursEtcE8hmWClLHOmZk2/KV+Tjoc48xjgNG0sX65pjSQQJh57hz2Uams1la2ZHJHeiXIxKnh1ETpOxcaH40VkZxh17cPnoLi1anhYSIINEOOivzym3i0POogI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775656784; c=relaxed/simple; bh=z/P2JrhV3K9AnBBmcmLBS5KUC3U6juyEb1STO03+wmE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fA25ftyWTrLbdffbM3nDULqGs+6TaaKA1IKDYh3RmNulrtX1QVh8DsfAMQNAEyRFnzzunIQXrZvn64AutloxxK6ngS1JKX/vXTmAXvlK1zYz/bayp1nRRL3Mgcv9Dp5EpNClgbyGMnSbE8W7w+qPHPMq/hwowz+PejYHrlrpaFE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C5244BA2E17 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775656784; 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=oF0TBWpnw1/pN1b6YeLh+f3clE7URADMSnDdm81+pCY=; b=g/ePBHdJNnISlyZApisqLLKlavIy6EqCqy1dAoOCpeO/s6nHL3DTX4kBm2G64y2hvb5pqJ pN3ZUXKU+Vf2OsrjD9tglyL2yWu/ZgVNDKOJAa6IrjHwMtGSSDi1gtM3TMKbU5KiQ9QtJ9 bQo1yxPOIpiTw03XUL8A5HfqTwU4t8s= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-694-49rDlLD1PPK3NHlA-OLnYA-1; Wed, 08 Apr 2026 09:59:42 -0400 X-MC-Unique: 49rDlLD1PPK3NHlA-OLnYA-1 X-Mimecast-MFC-AGG-ID: 49rDlLD1PPK3NHlA-OLnYA_1775656781 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A387A1956056; Wed, 8 Apr 2026 13:59:41 +0000 (UTC) Received: from localhost (unknown [10.44.50.40]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 106D919560A6; Wed, 8 Apr 2026 13:59:40 +0000 (UTC) From: =?utf-8?q?Tomasz_Kami=C5=84ski?= To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Defined __cpp_lib_replaceable_contract_violation_handler. Date: Wed, 8 Apr 2026 15:59:08 +0200 Message-ID: <20260408135939.266955-1-tkaminsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: SVEBkjKJEJmIvI4D-jTMEM3aA70DWBbY1otg0jnR2_w_1775656781 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, PROLO_LEO1, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SBL_CSS, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org This implements P3886R0: Wording for AT1-057, by defining the __cpp_lib_replaceable_contract_violation_handler. The macro is defined only if contracts are supported (i.e. under same conditions as __cpp_lib_contracts). GCC supports providing custom violation handler by providing an separate defintion of handle_contract_violation. This is supported on the targets that uses ELF format, so the macro is defined for with non-zero value for them. libstdc++-v3/ChangeLog: * include/bits/version.def (replaceable_contract_violation_handler) [(__cplusplus > 202302L) && (__cpp_contracts >= 202502L)]: Define to 202603 for ELF targets, and 0 otherwise. * include/bits/version.h: Regenerate. * include/std/contracts: Define __cpp_lib_replaceable_contract_violation_handler. --- From the discussion with Jason, this for sure is supported for ELF targets. We were not sure regarding Darwin, but we could always expand the set of targets where macro is defined. OK for trunk? libstdc++-v3/include/bits/version.def | 15 +++++++++++++++ libstdc++-v3/include/bits/version.h | 15 +++++++++++++++ libstdc++-v3/include/std/contracts | 1 + 3 files changed, 31 insertions(+) diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index cfb90533ce4..65a1d6d2660 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -2351,6 +2351,21 @@ ftms = { }; }; +ftms = { + name = replaceable_contract_violation_handler; + values = { + v = 202603; + cxxmin = 26; + extra_cond = "__cpp_contracts >= 202502L " + "&& __ELF__"; + }; + values = { + v = 0; + cxxmin = 26; + extra_cond = "__cpp_contracts >= 202502L"; + }; +}; + ftms = { name = simd; values = { diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 22dd31b9d32..4059a8a767b 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -2626,6 +2626,21 @@ #endif /* !defined(__cpp_lib_contracts) */ #undef __glibcxx_want_contracts +#if !defined(__cpp_lib_replaceable_contract_violation_handler) +# if (__cplusplus > 202302L) && (__cpp_contracts >= 202502L && __ELF__) +# define __glibcxx_replaceable_contract_violation_handler 202603L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_replaceable_contract_violation_handler) +# define __cpp_lib_replaceable_contract_violation_handler 202603L +# endif +# elif (__cplusplus > 202302L) && (__cpp_contracts >= 202502L) +# define __glibcxx_replaceable_contract_violation_handler 0L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_replaceable_contract_violation_handler) +# define __cpp_lib_replaceable_contract_violation_handler 0L +# endif +# endif +#endif /* !defined(__cpp_lib_replaceable_contract_violation_handler) */ +#undef __glibcxx_want_replaceable_contract_violation_handler + #if !defined(__cpp_lib_simd) # if (__cplusplus > 202302L) && _GLIBCXX_HOSTED && (__cpp_structured_bindings >= 202411L && __cpp_expansion_statements >= 202411L && __SSE2__) # define __glibcxx_simd 202506L diff --git a/libstdc++-v3/include/std/contracts b/libstdc++-v3/include/std/contracts index c1fe54750af..a0575fbefd9 100644 --- a/libstdc++-v3/include/std/contracts +++ b/libstdc++-v3/include/std/contracts @@ -33,6 +33,7 @@ #pragma GCC system_header #define __glibcxx_want_contracts +#define __glibcxx_want_replaceable_contract_violation_handler #include #ifdef __cpp_lib_contracts