logging: add a LogConfig::update() method
[folly.git] / folly / CPortability.h
index 1a47d2518ad6d447260da0a4c6e4ef69cd2c1f34..cba31683dff3251e41bf949fe397a412befee199 100644 (file)
 # endif
 #endif
 
+// portable version check for clang
+#ifndef __CLANG_PREREQ
+# if defined __clang__ && defined __clang_major__ && defined __clang_minor__
+/* nolint */
+#  define __CLANG_PREREQ(maj, min) \
+    ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
+# else
+/* nolint */
+#  define __CLANG_PREREQ(maj, min) 0
+# endif
+#endif
+
+#if defined(__has_builtin)
+#define FOLLY_HAS_BUILTIN(...) __has_builtin(__VA_ARGS__)
+#else
+#define FOLLY_HAS_BUILTIN(...) 0
+#endif
+
+#if defined(__has_feature)
+#define FOLLY_HAS_FEATURE(...) __has_feature(__VA_ARGS__)
+#else
+#define FOLLY_HAS_FEATURE(...) 0
+#endif
+
 /* Define a convenience macro to test when address sanitizer is being used
  * across the different compilers (e.g. clang, gcc) */
-#if defined(__clang__)
-# if __has_feature(address_sanitizer)
-#  define FOLLY_SANITIZE_ADDRESS 1
-# endif
-#elif defined (__GNUC__) && \
-      (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ >= 5)) && \
-      __SANITIZE_ADDRESS__
+#if FOLLY_HAS_FEATURE(address_sanitizer) || __SANITIZE_ADDRESS__
 # define FOLLY_SANITIZE_ADDRESS 1
 #endif
 
 
 /* Define a convenience macro to test when thread sanitizer is being used
  * across the different compilers (e.g. clang, gcc) */
-#if defined(__clang__)
-# if __has_feature(thread_sanitizer)
-#  define FOLLY_SANITIZE_THREAD 1
-# endif
-#elif defined(__GNUC__) && __SANITIZE_THREAD__
+#if FOLLY_HAS_FEATURE(thread_sanitizer) || __SANITIZE_THREAD__
 # define FOLLY_SANITIZE_THREAD 1
 #endif