C++ Logo

sg15

Advanced search

Re: [isocpp-sg15] [isocpp-sg21] P3835 -- Different contract checking for different libraries

From: John Spicer <jhs_at_[hidden]>
Date: Mon, 20 Oct 2025 11:08:08 -0400
The important point is that to get an ODR violation you have to do something wrong that might cause your program to work incorrectly.

Some tools can detect this and some tools can’t.

The important difference with contracts is that they cause your program to do something unexpected even though you didn’t do anything “wrong” according to the standard.

If you combine code compiled with different semantics, you have no idea which version of the code will be used.

Note that even if you are using Gašper’s all-knowing linker, there will only be one copy of the function in the end, and it will not meet the expectations of some of the callers.

John.

> On Oct 20, 2025, at 9:53 AM, Ville Voutilainen via SG21 <sg21_at_[hidden]> wrote:
>
> On Mon, 20 Oct 2025 at 16:46, Oliver Rosten
> <oliver.rosten_at_[hidden]> wrote:
>>
>> Hi John,
>>
>> I'm not convinced by this:
>>
>>> No, it is not a pre-existing problem.
>>> Other than contracts, if you end up with different function definitions it is an ODR violation and your program is IFNDR and can be rejected by your tools.
>>
>>
>> There's a difference between "can be in principle" and "is in general practice". Is it not the case that, in most instances, for all practical purposes there is no difference between an ODR violation that's IFNDR and the contracts mixed-mode: you get what the linker gives you?
>
> See, for example,
> https://devblogs.microsoft.com/oldnewthing/20160803-00/?p=94015
> See also https://maskray.me/blog/2022-11-13-odr-violation-detection
> _______________________________________________
> SG21 mailing list
> SG21_at_[hidden]
> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/sg21
> Link to this post: http://lists.isocpp.org/sg21/2025/10/11454.php

Received on 2025-10-20 15:08:21