Question:
Following piece of code does not work right on Alpine Linux:Error:
__cpp_lib_uncaught_exceptions
feature. Why this could happen?Answer:
I see a few issues with your code:__cpp_lib_uncaught_exceptions
is only documented to be defined (when applicable) if you’ve#include
-ed<version>
or<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 itinline
,static
or both, so every.cpp
file 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.cpp
file includes<exception>
/<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!