From 229ee34eea82ede6c87b3e88c9b1972b42f38c31 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 20 Jan 2018 17:54:06 -0800 Subject: [PATCH] Fix compiler warnings --- include/fmt/core.h | 23 +++++++++++++++++------ include/fmt/format.h | 2 +- include/fmt/posix.h | 4 ++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 21be70e0..900d0464 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -46,19 +46,30 @@ # define FMT_USE_NOEXCEPT 0 #endif +#if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ + (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || \ + FMT_MSC_VER >= 1900 +# define FMT_DETECTED_NOEXCEPT noexcept +#else +# define FMT_DETECTED_NOEXCEPT throw() +#endif + #ifndef FMT_NOEXCEPT # if FMT_EXCEPTIONS -# if FMT_USE_NOEXCEPT || FMT_HAS_FEATURE(cxx_noexcept) || \ - FMT_GCC_VERSION >= 408 || FMT_MSC_VER >= 1900 -# define FMT_NOEXCEPT noexcept -# else -# define FMT_NOEXCEPT throw() -# endif +# define FMT_NOEXCEPT FMT_DETECTED_NOEXCEPT # else # define FMT_NOEXCEPT # endif #endif +// This is needed because GCC still uses throw() in its headers when exceptions +// are disabled. +#if FMT_GCC_VERSION +# define FMT_DTOR_NOEXCEPT FMT_DETECTED_NOEXCEPT +#else +# define FMT_DTOR_NOEXCEPT FMT_NOEXCEPT +#endif + #if !defined(FMT_HEADER_ONLY) && defined(_WIN32) # ifdef FMT_EXPORT # define FMT_API __declspec(dllexport) diff --git a/include/fmt/format.h b/include/fmt/format.h index d669044e..b87826db 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2104,7 +2104,7 @@ class system_error : public std::runtime_error { init(error_code, message, make_args(args...)); } - ~system_error() throw(); + ~system_error() FMT_DTOR_NOEXCEPT; int error_code() const { return error_code_; } }; diff --git a/include/fmt/posix.h b/include/fmt/posix.h index 3e4edbea..2cf838d7 100644 --- a/include/fmt/posix.h +++ b/include/fmt/posix.h @@ -137,7 +137,7 @@ class BufferedFile { BufferedFile() FMT_NOEXCEPT : file_(0) {} // Destroys the object closing the file it represents if any. - ~BufferedFile() FMT_NOEXCEPT; + ~BufferedFile() FMT_DTOR_NOEXCEPT; #if !FMT_USE_RVALUE_REFERENCES // Emulate a move constructor and a move assignment operator if rvalue @@ -310,7 +310,7 @@ class File { #endif // Destroys the object closing the file it represents if any. - ~File() FMT_NOEXCEPT; + ~File() FMT_DTOR_NOEXCEPT; // Returns the file descriptor. int descriptor() const FMT_NOEXCEPT { return fd_; }