Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix symbol leak #3627

Merged
merged 1 commit into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +102 to +107
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should introduce a new macro. Let's update FMT_VISIBILITY instead since we shouldn't be changing visibility in general when not compiling a shared library.

Copy link
Contributor Author

@phprus phprus Sep 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vitaut
FMT_VISIBILITY is used unconditionally:

fmt/include/fmt/format.h

Lines 1883 to 1885 in a4b7b24

/* Use the hidden visibility as a workaround for a GCC bug (#1973). */ \
/* Use a macro-like name to avoid shadowing warnings. */ \
struct FMT_VISIBILITY("hidden") FMT_COMPILE_STRING : base { \

Therefore, we need two macros.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, we can simplify this later.


#ifdef __has_builtin
# define FMT_HAS_BUILTIN(x) __has_builtin(x)
#else
Expand Down Expand Up @@ -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;
};
Expand Down
4 changes: 4 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {{"));
Expand Down