summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2013-09-04 14:22:20 +0300
committerTor Lillqvist <tml@collabora.com>2013-09-04 15:00:03 +0300
commit78d09575da61ac681f708ee76fc239111aa7186e (patch)
treeb908e540134f31adf72874b7e337af959b660acc
parent290bfcd2fdb44a52943f6fdc134d2565cbb83db3 (diff)
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
-rw-r--r--include/sal/types.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/sal/types.h b/include/sal/types.h
index 145d47e20d82..c7a61bd06106 100644
--- a/include/sal/types.h
+++ b/include/sal/types.h
@@ -512,6 +512,34 @@ template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) {
# define SAL_WNODEPRECATED_DECLARATIONS_POP
#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.
An unused parameter is required if the function needs to adhere to a given