From 016b1faede70ff2e902ccd586f70fc37fcd45f3f Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Sat, 16 Sep 2023 19:26:36 +0500 Subject: [PATCH] Fix symbol leak (#3627) Signed-off-by: Vladislav Shchapov --- include/fmt/format.h | 9 ++++++++- test/format-test.cc | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 9d406d50..277c6b48 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -99,6 +99,13 @@ # define FMT_VISIBILITY(value) #endif +#if !defined(FMT_HEADER_ONLY) && !defined(_WIN32) && \ + (defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)) +# define FMT_INLINE_API FMT_VISIBILITY("default") +#else +# define FMT_INLINE_API +#endif + #ifdef __has_builtin # define FMT_HAS_BUILTIN(x) __has_builtin(x) #else @@ -1046,7 +1053,7 @@ FMT_BEGIN_EXPORT #endif /** An error reported from a formatting function. */ -class FMT_VISIBILITY("default") format_error : public std::runtime_error { +class FMT_INLINE_API format_error : public std::runtime_error { public: using std::runtime_error::runtime_error; }; diff --git a/test/format-test.cc b/test/format-test.cc index aef2d697..5b99c5c7 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -443,6 +443,10 @@ TEST(memory_buffer_test, max_size_allocator_overflow) { EXPECT_THROW(buffer.resize(161), std::exception); } +TEST(format_test, exception_from_lib) { + EXPECT_THROW_MSG(fmt::throw_format_error("test"), format_error, "test"); +} + TEST(format_test, escape) { EXPECT_EQ("{", fmt::format("{{")); EXPECT_EQ("before {", fmt::format("before {{"));