Skip to content

Commit

Permalink
Squelch MSVC warning exporting subclasses of runtime_error
Browse files Browse the repository at this point in the history
Based on pr fmtlib#1433 with changes to deal with issue fmtlib#1450

"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."

Puts a pragma before the relevant class def instead of within it's
declaration for greater support among older msvc.
  • Loading branch information
www committed Dec 10, 2019
1 parent 9f2e7ed commit 8a5cefb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@
#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)
Expand Down
7 changes: 5 additions & 2 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#ifndef FMT_FORMAT_H_
#define FMT_FORMAT_H_

#include "core.h"

#include <algorithm>
#include <cerrno>
#include <cmath>
Expand All @@ -43,6 +41,9 @@
#include <memory>
#include <stdexcept>

#include "core.h"


#ifdef __clang__
# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
#else
Expand Down Expand Up @@ -688,6 +689,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 @@ -2699,6 +2701,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 8a5cefb

Please sign in to comment.