HowardHinnant / date

A date and time library based on the C++11/14/17 <chrono> header
Other
3.08k stars 669 forks source link

C4996 warnings with Visual Studio 2019 #449

Open emptyVoid opened 5 years ago

emptyVoid commented 5 years ago

I'm getting this warning when trying to compile code using date with Visual Studio 2019:

C:\vcpkg-master\installed\x64-windows\include\date\date.h(1050): error C4996: 'std::uncaught_exception': warning STL4006: std::uncaught_exception() is deprecated in C++17. It is superseded by std::uncaught_exceptions(), plural. You can define _SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning.

Please note, this line: https://github.com/HowardHinnant/date/blob/8a563041fa65146531249ed557a6839809488521/include/date/date.h#L99

does not work in general case (e.g. when <exception> gets included before <date/date.h>).

HAS_UNCAUGHT_EXCEPTIONS should probably be adjusted is the same manner as HAS_STRING_VIEW: https://github.com/HowardHinnant/date/blob/8a563041fa65146531249ed557a6839809488521/include/date/date.h#L35

HowardHinnant commented 5 years ago

Ok, thanks.

You can also define HAS_UNCAUGHT_EXCEPTIONS=1 on the command line or with your IDE to override its default behavior in date.h.

emptyVoid commented 5 years ago

I've just noticed: https://github.com/HowardHinnant/date/blob/a029f1105d27b95c58bade4538c3238a199d86d1/include/date/date.h#L138 Shouldn't it be __cplusplus >= 201703? Am I missing something?

HowardHinnant commented 5 years ago

I've had it both ways, and proved the old saying: You can't make everyone happy. :-)

With it as __cplusplus >= 201703 people complained about their binary not being ABI compatible with older versions of an OS. So I set it such that it triggers on the removal of uncaught_exception instead of on the introduction of uncaught_exceptions. With the fallback that people can set it however they want with HAS_UNCAUGHT_EXCEPTIONS.

emptyVoid commented 5 years ago

Oh, I see. Thanks for clarifying!