summaryrefslogtreecommitdiff
path: root/lib/compiler.h
diff options
context:
space:
mode:
authorGurucharan Shetty <gshetty@nicira.com>2014-09-15 12:58:09 -0700
committerGurucharan Shetty <gshetty@nicira.com>2014-09-15 15:15:35 -0700
commit270f328621bfd8f80659150d5d3eec51754b5bfb (patch)
treec068c18ce82dcee21750e55f61ee2b3e4e157064 /lib/compiler.h
parentd72eff6cec01187d9b6b0f8befdbdec0943e6012 (diff)
downloadopenvswitch-270f328621bfd8f80659150d5d3eec51754b5bfb.tar.gz
compiler: Define NO_RETURN for MSVC.
To prevent warnings such as "Not all control paths return a value", we should define NO_RETURN for MSVC. Currently for gcc, we add NO_RETURN at the end of function declaration. But for MSVC, "__declspec(noreturn)" is needed at the beginning of function declaration. So this commit moves NO_RETURN to the beginning of the function declaration as it works with gcc and clang too. Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/compiler.h')
-rw-r--r--lib/compiler.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/compiler.h b/lib/compiler.h
index 5942c3029..629d09bf8 100644
--- a/lib/compiler.h
+++ b/lib/compiler.h
@@ -24,8 +24,17 @@
#define __has_extension(x) 0
#endif
+/* To make NO_RETURN portable across gcc/clang and MSVC, it should be
+ * added at the beginning of the function declaration. */
#if __GNUC__ && !__CHECKER__
#define NO_RETURN __attribute__((__noreturn__))
+#elif _MSC_VER
+#define NO_RETURN __declspec(noreturn)
+#else
+#define NO_RETURN
+#endif
+
+#if __GNUC__ && !__CHECKER__
#define OVS_UNUSED __attribute__((__unused__))
#define PRINTF_FORMAT(FMT, ARG1) __attribute__((__format__(printf, FMT, ARG1)))
#define SCANF_FORMAT(FMT, ARG1) __attribute__((__format__(scanf, FMT, ARG1)))
@@ -37,7 +46,6 @@
#define OVS_LIKELY(CONDITION) __builtin_expect(!!(CONDITION), 1)
#define OVS_UNLIKELY(CONDITION) __builtin_expect(!!(CONDITION), 0)
#else
-#define NO_RETURN
#define OVS_UNUSED
#define PRINTF_FORMAT(FMT, ARG1)
#define SCANF_FORMAT(FMT, ARG1)