Date: Tue, 18 Aug 2026 20:33:08 +0100
On 16/08/2026 20:44, Ville Voutilainen wrote:
> On Sun, 16 Aug 2026 at 00:31, Jonathan Grant via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
>
>> As an experiment, I have implemented contract-like checks in terms of compile_assert().
>> https://github.com/jonnygrant/compile_assert/blob/main/testsuite/main28_a.cpp
>
> For what it's worth:
> https://godbolt.org/z/WdbbaGsz1
>
> This one isn't sensitive to how much is inlined or not. Which also
> means it doesn't benefit any from any inlining
> or other optimization. Which means it's not a complete replacement for
> your compile_assert.
I commented in the intentional error on line 40, it does identify at compile time in this example. Makes me wonder how well it would work on a large project.
<source>: In function 'int main()':
<source>:40:17: error: argument '1.8e+2' provably violates the precondition of 'void Number::decrease_by(double)'
40 | n.decrease_by (180.0);
| ~~~~~~~~~~~~~~^~~~~~~
<source>:20:8: note: declared here
20 | void decrease_by (double percentage)
| ^~~~~~~~~~~
ASM generation compiler returned: 1
<source>: In function 'int main()':
<source>:40:17: error: argument '1.8e+2' provably violates the precondition of 'void Number::decrease_by(double)'
40 | n.decrease_by (180.0);
| ~~~~~~~~~~~~~~^~~~~~~
<source>:20:8: note: declared here
20 | void decrease_by (double percentage)
| ^~~~~~~~~~~
Execution build compiler returned: 1
Build failed
> On Sun, 16 Aug 2026 at 00:31, Jonathan Grant via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
>
>> As an experiment, I have implemented contract-like checks in terms of compile_assert().
>> https://github.com/jonnygrant/compile_assert/blob/main/testsuite/main28_a.cpp
>
> For what it's worth:
> https://godbolt.org/z/WdbbaGsz1
>
> This one isn't sensitive to how much is inlined or not. Which also
> means it doesn't benefit any from any inlining
> or other optimization. Which means it's not a complete replacement for
> your compile_assert.
I commented in the intentional error on line 40, it does identify at compile time in this example. Makes me wonder how well it would work on a large project.
<source>: In function 'int main()':
<source>:40:17: error: argument '1.8e+2' provably violates the precondition of 'void Number::decrease_by(double)'
40 | n.decrease_by (180.0);
| ~~~~~~~~~~~~~~^~~~~~~
<source>:20:8: note: declared here
20 | void decrease_by (double percentage)
| ^~~~~~~~~~~
ASM generation compiler returned: 1
<source>: In function 'int main()':
<source>:40:17: error: argument '1.8e+2' provably violates the precondition of 'void Number::decrease_by(double)'
40 | n.decrease_by (180.0);
| ~~~~~~~~~~~~~~^~~~~~~
<source>:20:8: note: declared here
20 | void decrease_by (double percentage)
| ^~~~~~~~~~~
Execution build compiler returned: 1
Build failed
Received on 2026-08-18 19:33:15
