arximboldi/immer

__has_feature may not be accurate

tusooa opened this issue · 5 comments

For example, Qt will define this macro even if it was not defined.

/usr/include/qt5/QtCore/qcompilerdetection.h:516:#ifndef __has_feature
/usr/include/qt5/QtCore/qcompilerdetection.h:517:#  define __has_feature(x)             0
/usr/include/qt5/QtCore/qcompilerdetection.h-518-#endif

And looks like gcc version 9.3.0 (Gentoo 9.3.0-r1 p3) does not have __has_feature pre-defined.
So if immer headers are included after Qt headers, immer will deem that there is no exception supported, even if I use -fexceptions.

I guess we should at least allow user to always use exceptions (which is important for things like lager::lenses::at because it uses exception to fill in the optional).

@chuim, what do you think the best solution is here?

chuim commented

Thanks for looping me in. I have no experience on cross compiler support so I have no suggestion to propose. I can try to research a solution once I'm back from the holidays, early next year.

Cool, thanks!

chuim commented

GCC defines the __cpp_exceptions symbol if exceptions are enabled [1, 2]. I don't have a GCC setup I work with so I'd rather ask someone else to try updating the exception detection code in immer/config.hpp to also check for it.

Also, that snippet of code from Qt seems odd as it decides to override that macro with an always-false implementation what might mislead decisions from other macros in the code.

Hi @chuim, Thanks for investigating the issue!

Regarding the GCC setup, if you use the nix-shell as advised in the project README it is super easy to get one without polluting your environment. If you are on a Linux the default setup will use a GCC, on Mac you can try nix-shell --argstr toolchain gnu-9.