On Wed, 8 Apr 2026, 15:48 Florian Weimer, <[email protected]> wrote:

> * Tomasz Kamiński:
>
> > 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.
>
> Wouldn't you have to declare the symbol as weak in the header, so that
> multiple definitions won't conflict?
>

There is no declaration in the header.



> With ELF, there can only be one strong definition of a symbol in the
> link, and whether this works as expected depends on the contents of the
> object file that contains the symbol definition.
>
> Even if the symbol is defined as weak in the header, multiple TUs
> reacting to __cpp_lib_replaceable_contract_violation_handler need to
> coordinate.  A simple macro does not really capture that.  A library
> should not assume that because the macro is defined, replacing the
> handler has the intended effect, or is indeed successful.
>
> Thanks,
> Florian
>
>

Reply via email to