From 6c088be8ec6ffd6d1605a82b7e2cc0dde0e3d820 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 16 Sep 2023 07:40:08 -0700 Subject: [PATCH] Cleanup handling of visibility --- include/fmt/core.h | 14 ++++++++------ include/fmt/format.h | 16 +++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index f9e3b7d6..77c2d240 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -185,18 +185,20 @@ # define FMT_END_EXPORT #endif +#if FMT_GCC_VERSION || defined(__clang__) +# define FMT_VISIBILITY(value) __attribute__((visibility(value))) +#else +# define FMT_VISIBILITY(value) +#endif + #if !defined(FMT_HEADER_ONLY) && defined(_WIN32) # ifdef FMT_LIB_EXPORT # define FMT_API __declspec(dllexport) # elif defined(FMT_SHARED) # define FMT_API __declspec(dllimport) # endif -#else -# if defined(FMT_LIB_EXPORT) || defined(FMT_SHARED) -# if defined(__GNUC__) || defined(__clang__) -# define FMT_API __attribute__((visibility("default"))) -# endif -# endif +#elif defined(FMT_LIB_EXPORT) || defined(FMT_SHARED) +# define FMT_API FMT_VISIBILITY("default") #endif #ifndef FMT_API # define FMT_API diff --git a/include/fmt/format.h b/include/fmt/format.h index 277c6b48..fc61330d 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -93,17 +93,11 @@ # define FMT_NO_UNIQUE_ADDRESS #endif -#if FMT_GCC_VERSION || defined(__clang__) -# define FMT_VISIBILITY(value) __attribute__((visibility(value))) +// Visibility when compiled as a shared library/object. +#if defined(FMT_LIB_EXPORT) || defined(FMT_SHARED) +# define FMT_SO_VISIBILITY(value) FMT_VISIBILITY(value) #else -# define FMT_VISIBILITY(value) -#endif - -#if !defined(FMT_HEADER_ONLY) && !defined(_WIN32) && \ - (defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)) -# define FMT_INLINE_API FMT_VISIBILITY("default") -#else -# define FMT_INLINE_API +# define FMT_SO_VISIBILITY(value) #endif #ifdef __has_builtin @@ -1053,7 +1047,7 @@ FMT_BEGIN_EXPORT #endif /** An error reported from a formatting function. */ -class FMT_INLINE_API format_error : public std::runtime_error { +class FMT_SO_VISIBILITY("default") format_error : public std::runtime_error { public: using std::runtime_error::runtime_error; };