by superxpro12 · 2mo ago · 0 comments
What's wrong with static polymorphism that have been around for at least 31 years? (1995 per [1]). Also know as CRTP [2] Apart, of course, from ugly verbose compilation errors...
And now c++23 "deducing `this`" [3,4] modern replacement which is supposed to improve compilation time and remove the verbose errors.
[1] https://www.artima.com/articles/the-most-important-c-non-boo...
[2] https://en.cppreference.com/cpp/language/crtp
[3] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p08...
[4] https://devblogs.microsoft.com/cppblog/cpp23-deducing-this/
Take the example from the article. The contract trips at runtime, not at compile time.
There is a lot of interest in static analysis enforcing contracts, but this will likely require some additions to the contract specification.
By whole program analysis I mean you need the entire call tree of a function - stopping only when you can validate that the range of values is constrained to legal values. For some functions this is really simple, while for others the whole flow can be thousands of functions.
Also take a look at David Crocker's Escher Technologies "Escher C Verifier and Escher C++ Verifier" (https://www.eschertech.com/products/ecv.php) and articles on "Verified Design-By-Contract" etc. linked to in my comment chain here - https://news.ycombinator.com/item?id=48544022
Gcc can already do link-time devirtualization in some cases.