Skip to content

Commit

Permalink
Create separate dllexport marking points for clang and msvc. (#2229)
Browse files Browse the repository at this point in the history
* add FMT_INSTANTIATION_DEF_API for msvc

This should fix #2228

To fix difference dllexport requirements
msvc:  dllexport at template instantiation definition in format.cc
clang: dllexport at template instantiation declaration (extern template) in format.h
  • Loading branch information
denchat authored Apr 16, 2021
1 parent f4bbc54 commit 52bd62c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
15 changes: 13 additions & 2 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,19 @@
#ifndef FMT_EXTERN_TEMPLATE_API
# define FMT_EXTERN_TEMPLATE_API
#endif
#ifndef FMT_INSTANTIATION_DECL_API
# define FMT_INSTANTIATION_DECL_API FMT_API
#ifndef FMT_INSTANTIATION_DECL_API // clang marks dllexport at extern template.
# ifndef _MSC_VER
# define FMT_INSTANTIATION_DECL_API FMT_API
# else
# define FMT_INSTANTIATION_DECL_API
# endif
#endif
#ifndef FMT_INSTANTIATION_DEF_API // msvc marks dllexport at the definition itself.
# ifndef _MSC_VER
# define FMT_INSTANTIATION_DEF_API
# else
# define FMT_INSTANTIATION_DEF_API FMT_API
# endif
#endif

#ifndef FMT_HEADER_ONLY
Expand Down
2 changes: 2 additions & 0 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,9 @@ FMT_INLINE uint16_t bsr2log10(int bsr) {
return data[bsr];
}

#ifndef FMT_EXPORTED
FMT_EXTERN template struct FMT_INSTANTIATION_DECL_API basic_data<void>;
#endif

// This is a struct rather than an alias to avoid shadowing warnings in gcc.
struct data : basic_data<> {};
Expand Down
2 changes: 1 addition & 1 deletion src/format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ vformat_to(buffer<char>&, string_view,

// Clang doesn't allow dllexport on template instantiation definitions:
// https://reviews.llvm.org/D61118.
template struct detail::basic_data<void>;
template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>;

// Workaround a bug in MSVC2013 that prevents instantiation of format_float.
int (*instantiate_format_float)(double, int, detail::float_specs,
Expand Down

0 comments on commit 52bd62c

Please sign in to comment.