mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-08 02:28:15 +00:00
fix(Clang CodeGen): remove warnings
./fmt/fmt/format.h(308,10): warning : unknown pragma ignored [-Wunknown-pragmas] ^ 1 warning generated. format.cc In file included from fmt\fmt\format.cc:28: fmt\fmt/format.h(308,10): warning : unknown pragma ignored [-Wunknown-pragmas] ^ fmt\fmt\format.cc(165,17): warning : 'strerror' is deprecated: This function or variable may be unsafe. Consider using strerror_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [-Wdeprecated-declarations] buffer_ = strerror(error_code_); ^ C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\string.h(178,24) : note: 'strerror' has been explicitly marked deprecated here _ACRTIMP char* __cdecl strerror( ^ fmt\fmt\format.cc(78,37): warning : unused function 'strerror_s' [-Wunused-function] static inline fmt::internal::Null<> strerror_s(char *, std::size_t, ...) { ^ 3 warnings generated. refactor: use attribute to remove -Wunused-function warnings instead of dummy function call
This commit is contained in:
parent
9328a074b1
commit
708d9509ff
@ -72,9 +72,11 @@
|
||||
|
||||
// Dummy implementations of strerror_r and strerror_s called if corresponding
|
||||
// system functions are not available.
|
||||
FMT_MAYBE_UNUSED
|
||||
static inline fmt::internal::Null<> strerror_r(int, char *, ...) {
|
||||
return fmt::internal::Null<>();
|
||||
}
|
||||
FMT_MAYBE_UNUSED
|
||||
static inline fmt::internal::Null<> strerror_s(char *, std::size_t, ...) {
|
||||
return fmt::internal::Null<>();
|
||||
}
|
||||
@ -159,6 +161,11 @@ int safe_strerror(
|
||||
ERANGE : result;
|
||||
}
|
||||
|
||||
#ifdef __c2__
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
// Fallback to strerror if strerror_r and strerror_s are not available.
|
||||
int fallback(internal::Null<>) {
|
||||
errno = 0;
|
||||
@ -166,13 +173,15 @@ int safe_strerror(
|
||||
return errno;
|
||||
}
|
||||
|
||||
#ifdef __c2__
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
public:
|
||||
StrError(int err_code, char *&buf, std::size_t buf_size)
|
||||
: error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {}
|
||||
|
||||
int run() {
|
||||
// Suppress a warning about unused strerror_r.
|
||||
strerror_r(0, FMT_NULL, "");
|
||||
return handle(strerror_r(error_code_, buffer_, buffer_size_));
|
||||
}
|
||||
};
|
||||
|
23
fmt/format.h
23
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))
|
||||
@ -335,7 +352,10 @@ typedef __int64 intmax_t;
|
||||
|
||||
namespace fmt {
|
||||
namespace internal {
|
||||
// avoid Clang with Microsoft CodeGen's -Wunknown-pragmas warning
|
||||
# ifndef __clang__
|
||||
# pragma intrinsic(_BitScanReverse)
|
||||
# endif
|
||||
inline uint32_t clz(uint32_t x) {
|
||||
unsigned long r = 0;
|
||||
_BitScanReverse(&r, x);
|
||||
@ -349,7 +369,8 @@ inline uint32_t clz(uint32_t x) {
|
||||
}
|
||||
# define FMT_BUILTIN_CLZ(n) fmt::internal::clz(n)
|
||||
|
||||
# ifdef _WIN64
|
||||
// avoid Clang with Microsoft CodeGen's -Wunknown-pragmas warning
|
||||
# if defined(_WIN64) && !defined(__clang__)
|
||||
# pragma intrinsic(_BitScanReverse64)
|
||||
# endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user