From 70b14f197e06865d3e60ae4df5991b3021d1cdc8 Mon Sep 17 00:00:00 2001 From: owent Date: Fri, 13 May 2022 19:45:17 +0800 Subject: [PATCH] Fix compatibility of `OPENTELEMETRY_LIKELY_IF` Signed-off-by: owent --- api/include/opentelemetry/common/macros.h | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/api/include/opentelemetry/common/macros.h b/api/include/opentelemetry/common/macros.h index 231d5368f0..204c1ed04e 100644 --- a/api/include/opentelemetry/common/macros.h +++ b/api/include/opentelemetry/common/macros.h @@ -7,25 +7,14 @@ #include "opentelemetry/version.h" -#ifndef OPENTELEMETRY_LIKELY_IF -# if defined(__has_cpp_attribute) +#if !defined(OPENTELEMETRY_LIKELY_IF) && defined(__cplusplus) +// GCC 9 has likely attribute but do not support declare it at the beginning of statement +# if defined(__has_cpp_attribute) && (defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 9) # if __has_cpp_attribute(likely) # define OPENTELEMETRY_LIKELY_IF(...) \ if (__VA_ARGS__) \ [[likely]] # endif -# elif defined(__clang__) -# if __clang_major__ >= 12 -# define OPENTELEMETRY_LIKELY_IF(...) \ - if (__VA_ARGS__) \ - [[likely]] -# endif -# elif defined(__GNUC__) -# if __GNUC__ >= 9 -# define OPENTELEMETRY_LIKELY_IF(...) \ - if (__VA_ARGS__) \ - [[likely]] -# endif # endif #endif #if !defined(OPENTELEMETRY_LIKELY_IF) && (defined(__clang__) || defined(__GNUC__))