c++ - Prevent or generate warning for custom deprecations -


i'm using c++11's static_assert perform compile-time checks prevent use of insecure functions, and/or provide feedback user when new feature should used , relevant apis out of date (e.g. using std::strftime, std::to_string, etc.).

i want force failure if source code attempts use outdated functions, need totally cross-platform, , bypass or workaround other 'helpers' such microsofts own deprecations.

i see can use .sections when working gnu toolchain, can see definition in openbsd's cdefs.h (http://ninjalj.blogspot.co.uk/2011/11/your-own-linker-warnings-using-gnu.html) have nothing equivalent visual studio.

for example, can use following code without problem prevent strcpy/strcat:

#   define compile_time_check(expression, message)      static_assert(expression, message) #   define guarantee_failure            (0 == 1) #   define disabled_functions_message_cstring   "strcpy, strcat must replaced strlcpy , strlcat, respectively" #   define strcat       compile_time_check(guarantee_failure, disabled_functions_message_cstring); 

it may unclean works; trouble when attempting same others don't play nicely, such ctime , localtime:

_crt_insecure_deprecate(localtime_s) static __inline struct tm * __crtdecl localtime(const time_t * _time)  1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\time.inl(86): error c2059: syntax error : 'static_assert' 

is there way can block specific functions (warning or compile failure), while providing message use in place, without conflict gcc/visual studio in suitable way? crt macros in visual studio not prevent above error aforementioned defines.

i'm not convinced __declspec(deprecated) int strcpy(char*,char*); (as noted here: c++ mark deprecated) going play ball, , lot more work & less descriptive setting define function name.

you can use disable:warning {#warning code}


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -