diff --git a/fmt/format.cc b/fmt/format.cc index ff960eae..4dd408b3 100644 --- a/fmt/format.cc +++ b/fmt/format.cc @@ -72,10 +72,10 @@ // Dummy implementations of strerror_r and strerror_s called if corresponding // system functions are not available. -static inline fmt::internal::Null<> strerror_r(int, char *, ...) { +FMT_MAYBE_UNUSED static inline fmt::internal::Null<> strerror_r(int, char *, ...) { return fmt::internal::Null<>(); } -static inline fmt::internal::Null<> strerror_s(char *, std::size_t, ...) { +FMT_MAYBE_UNUSED static inline fmt::internal::Null<> strerror_s(char *, std::size_t, ...) { return fmt::internal::Null<>(); } @@ -180,9 +180,6 @@ int safe_strerror( : error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {} int run() { - // Suppress a warning about unused strerror_r and strerror_s. - strerror_r(0, FMT_NULL, ""); - strerror_s(FMT_NULL, 0, ""); return handle(strerror_r(error_code_, buffer_, buffer_size_)); } }; diff --git a/fmt/format.h b/fmt/format.h index c91bbf60..8b653fc0 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -153,6 +153,23 @@ typedef __int64 intmax_t; # define FMT_HAS_CPP_ATTRIBUTE(x) 0 #endif +#if FMT_HAS_CPP_ATTRIBUTE(maybe_unused) +# define FMT_HAS_CXX17_ATTRIBUTE_MAYBE_UNUSED +// VC++ 1910 support /std: option and that will set _MSVC_LANG macro +// Clang with Microsoft CodeGen doesn't define _MSVC_LANG macro +#elif defined(_MSVC_LANG) && _MSVC_LANG > 201402 +# define FMT_HAS_CXX17_ATTRIBUTE_MAYBE_UNUSED +#endif + +#ifdef FMT_HAS_CXX17_ATTRIBUTE_MAYBE_UNUSED +# define FMT_MAYBE_UNUSED [[maybe_unused]] +// g++/clang++ also support [[gnu::unused]]. However, we don't use it. +#elif defined(__GNUC__) +# define FMT_MAYBE_UNUSED __attribute__((unused)) +#else +#define FMT_MAYBE_UNUSED +#endif + // Use the compiler's attribute noreturn #if defined(__MINGW32__) || defined(__MINGW64__) # define FMT_NORETURN __attribute__((noreturn))