Question:Following piece of code does not work right on Alpine Linux:
__cpp_lib_uncaught_exceptionsfeature. Why this could happen?
Answer:I see a few issues with your code:
__cpp_lib_uncaught_exceptionsis only documented to be defined (when applicable) if you’ve
<exception>; you’ve included neither. Add
#include <exceptions>above that feature test somewhere, and it should work.
Your code as written will redefine
uncaught_exceptions()in every compilation unit that includes it when the macro is not defined, because you made the definition in a header and did not make it
staticor both, so every
.cppfile including your header ends up getting its own exportable definition. Without the necessary headers included in your header, whether that feature test macro is defined will depend on whether each
<version>, and whether it does so before or after including your header. If they aren’t uniform, some files could get your header’s definition, while others get the built-in definition.
If you have better answer, please add a comment about this, thank you!