Re:C++'s `Noexcept` Can (Sometimes) Help (Or Hurt) Performance
by Arech on Tuesday August 06, 2024 @12:43PM
(#41172560)
Yes, true, thanks. I confused "will it throw given inputs&state?" with "can it potentially throw?".
I wonder, why compilers don't expose that information? Some operator returning tri-state "this code provably doesn't throw | could throw | can't see, break the compilation" could help writing generic code immensely. Instead we have to resolve to multi-storey noexcept() operator inside a noexcept qualifier which is very detrimental for the code readability...
Re:C++'s `Noexcept` Can (Sometimes) Help (Or Hurt) Performance
by Arech on Tuesday August 06, 2024 @01:02PM
(#41172779)
Interestingly, AUTOSAR C++14 Guidance (https://www.autosar.org/fileadmin/standards/R22-11/AP/AUTOSA...) had a "Rule A15-4-4 (required, implementation, automated) A declaration of non-throwing function shall contain noexcept specification." which was thankfully removed in MISRA C++2023 (the latest guidance for C++17, can't give a link, it's a paid document), - it mandates it only for a few special functions (destructors, move constructors/assignments and a few more).
Noexcept on the surface is useful, except for the terminate guarantee, which requires a ton of work to avoid metadata size growth and hurts inlining. If violations of noexcept were UB and it was a pure optimization hint the world would be much better