For certain reasons we should not use certain std functions like std::sort()
in our code base (we have our own implementations for those).
Is there a way to prevent calls to those functions, preferably by raising an error at compile time?
I looked at overriding std functions but it leads to undefined behavior.
You shouldn't try override o change functions in a standard library since in the first case you will have ODR violation and in the second case some of the thirdparties may used in your project may be affected.
I would suggest you to create a custom check for clang-tidy and add a CI job to run it on your codebase. This will take some time but I believe this is the best option.
There's no way you can mark any of the standard functions as unwanted in your code base.
You can do regular code reviews, or use a configurable static analysis tool to check committed code for usage of the unwanted functions though.
The latter only makes sense with an established CI process for your software.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With