Skip to content

Commit

Permalink
Squelch MSVC warning exporting subclasses of runtime_error (fix for PR
Browse files Browse the repository at this point in the history
…#1433) (#1470)

* Squelch MSVC warning exporting subclasses of runtime_error

When compiling {fmt} as a DLL, MSVC complains that we are exporting
classes that inherit from "std::runtime_error", which we are not
exporting.

In this case, it's not really a problem because that symbol is already
exported via the C++ stdlib. So we just add a pragma to silence the
warning.

* Fix compilation with MinGW

Commit 3bc28fc ("Squelch MSVC warning exporting subclasses of
runtime_error", 2019-11-29) silenced a MSVC warning under. The MinGW
compiler also defines _WIN32, but does not support the "warning" pragma.

Introduce a helper macro to squelch the MSVC warning only when using the
Microsoft compiler.

Signed-off-by: Beat Bolli <[email protected]>

* Fix compilation with VS2015 (#1450)

VS2015 does not support the __pragma(...) syntax in the midst of a
class declaration, so move it to just before the declaration.
  • Loading branch information
iPherian authored and vitaut committed Dec 13, 2019
1 parent a770009 commit 8ab1c5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,22 @@
#endif

#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
# if FMT_MSC_VER
# define FMT_NO_W4275 __pragma(warning(suppress : 4275))
# else
# define FMT_NO_W4275
# endif
# define FMT_CLASS_API FMT_NO_W4275
# ifdef FMT_EXPORT
# define FMT_API __declspec(dllexport)
# elif defined(FMT_SHARED)
# define FMT_API __declspec(dllimport)
# define FMT_EXTERN_TEMPLATE_API FMT_API
# endif
#endif
#ifndef FMT_CLASS_API
# define FMT_CLASS_API
#endif
#ifndef FMT_API
# define FMT_API
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ using memory_buffer = basic_memory_buffer<char>;
using wmemory_buffer = basic_memory_buffer<wchar_t>;

/** A formatting error such as invalid format string. */
FMT_CLASS_API
class FMT_API format_error : public std::runtime_error {
public:
explicit format_error(const char* message) : std::runtime_error(message) {}
Expand Down Expand Up @@ -2707,6 +2708,7 @@ class arg_formatter : public internal::arg_formatter_base<Range> {
An error returned by an operating system or a language runtime,
for example a file opening error.
*/
FMT_CLASS_API
class FMT_API system_error : public std::runtime_error {
private:
void init(int err_code, string_view format_str, format_args args);
Expand Down

0 comments on commit 8ab1c5c

Please sign in to comment.