Kaydet (Commit) 78d09575 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

Add SAL_WNOUNREACHABLE_CODE_PUSH and _POP macros

To be used around code where some compiler, in some circumstances,
generates bogus warnings about unreachable code, that it would be much
uglier to work around otherwise.

Specifically, I will at first now use this to get rid of MSVC warnings
about unreachable code when calling a function defined in another
source file (but going into the same library) that always throws. The
compiler notices this when one uses link-time code generation and it
thus can do global inlining of code from all compilation units that go
into a library (or executable).

For MSVC, the __pragma that the SAL_WNOUNREACHABLE_CODE_PUSH macro
expands to needs to be in force at the start curly brace of a
function, so place the PUSH macro before the function definition. For
clarity, I guess it is best that the corresponding POP macro comes
after the end of the function.

Change-Id: Icef5259c5360b9facdc136fec1f207665ce79d90
üst 290bfcd2
...@@ -512,6 +512,34 @@ template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) { ...@@ -512,6 +512,34 @@ template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) {
# define SAL_WNODEPRECATED_DECLARATIONS_POP # define SAL_WNODEPRECATED_DECLARATIONS_POP
#endif #endif
/**
Use as follows:
SAL_WNOUNREACHABLE_CODE_PUSH
function definition
SAL_WNOUNREACHABLE_CODE_POP
Useful in cases where the compiler is "too clever" like when doing
link-time code generation, and noticing that a called function
always throws, and fixing the problem cleanly so that it produceds
no warnings in normal non-LTO compilations either is not easy.
*/
#ifdef _MSC_VER
#define SAL_WNOUNREACHABLE_CODE_PUSH \
__pragma(warning(push)) \
__pragma(warning(disable:4702))
#define SAL_WNOUNREACHABLE_CODE_POP \
__pragma(warning(pop))
#else
/* Add definitions for GCC and Clang if needed */
#define SAL_WNOUNREACHABLE_CODE_PUSH
#define SAL_WNOUNREACHABLE_CODE_POP
#endif
/** Annotate unused but required C++ function parameters. /** Annotate unused but required C++ function parameters.
An unused parameter is required if the function needs to adhere to a given An unused parameter is required if the function needs to adhere to a given
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment