[PATCH] libstdc++: Defined __cpp_lib_replaceable_contract_violation_handler.

Jonathan Wakely jwakely@redhat.com
Mon Apr 13 10:41:31 GMT 2026


On Wed, 8 Apr 2026 at 15:03, Tomasz Kamiński <tkaminsk@redhat.com> wrote:
>
> 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?

OK


>
>  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 <bits/version.h>
>
>  #ifdef __cpp_lib_contracts
> --
> 2.53.0
>



More information about the Libstdc++ mailing list