Do you propose to recommend/specify to the compiler at the caller site, which optimizations can be selected?
If the function is not inlined and you want to use a different function entry point to skip some code and branches, then it would be quite random, whether that is possible.
- If the function is not generated in the same translation unit, the object files or libraries have to somehow store those entry points.
- The compiler would be much more effective to generate that flexibility, if it had a notion or list of possible assurances
- Beside assert/assume/contracts there is also the possibility to provide boolean expressions as function parameters or template parameters or as overloaded parameter types
sqrt(positivedouble d)
sqrt(double d, bool positive = false)
template<bool positive = false> sqrt(double d)
You would have to specify, how your solution is different and what improvements it brings to the table.
-----Ursprüngliche Nachricht-----
Von: SD SH <Z5515zwy@outlook.com>
Gesendet: So 01.06.2025 17:32
Betreff: 回复: [std-proposals] A Proposal about A New Keyword assure
An: std-proposals@lists.isocpp.org;
CC: Sebastian Wittmeier <wittmeier@projectalpha.org>;
True, but not only inlined functions.It can make compiler jump to the excepted branch without redundant check-ups. We can even use 1 function and many tag.Like this:_func:; fastcall; rcx = int para1; rdx = bool para2cmp rdx, 0jne _func_para2_truecmp rcx, 0jl _func_para2_true_para1_l0_func_para2_false_para1_geq0; ...ret_func_para2_true:; ...ret_func_para2_true_para1_l0:; ...retIn fact, even if compiler not inlined the function, it still works.For example, _func(i assure(i >= 0, b assure(!b)) will be:call _func_para2_false_para1_geq0And 2 branches will be skipped.I think compiler couldn't do above well.