compiler: Define NO_RETURN for MSVC.
[cascardo/ovs.git] / lib / compiler.h
index 5942c30..629d09b 100644 (file)
   #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)