Module linkage fixes for shared build (#4169)

* Mark some in-class defined member functions as explicitly inline/constexpr, to avoid missing external symbols when using fmt module with shared build due to modules not defaulting to implicit inline.

* Switch constexpr to inline for context::arg(string_view).
NOTE: Looks as if basic_format_args::get(string_view) could probably be made constexpr instead, but sticking with minimal change approach.

* Work around apparent non-conformance of older MSVC compilers.

* Switch format_int::str() from constexpr to inline to satisfy libstdc++ std::string constexpr limitations.

* Replace usages of macros for constexpr/inline with keywords.

* Fix for locations requiring C++14 constexpr.

* Further minor constexpr tweaks.

* Apply clang format
This commit is contained in:
Cameron Angus
2024-09-26 07:53:55 -07:00
committed by GitHub
parent 891c9a73ae
commit 96dca569a1
5 changed files with 63 additions and 58 deletions
+9 -9
View File
@@ -1788,9 +1788,9 @@ template <typename T> class buffer {
};
struct buffer_traits {
explicit buffer_traits(size_t) {}
auto count() const -> size_t { return 0; }
auto limit(size_t size) -> size_t { return size; }
constexpr explicit buffer_traits(size_t) {}
constexpr auto count() const -> size_t { return 0; }
constexpr auto limit(size_t size) const -> size_t { return size; }
};
class fixed_buffer_traits {
@@ -1799,9 +1799,9 @@ class fixed_buffer_traits {
size_t limit_;
public:
explicit fixed_buffer_traits(size_t limit) : limit_(limit) {}
auto count() const -> size_t { return count_; }
auto limit(size_t size) -> size_t {
constexpr explicit fixed_buffer_traits(size_t limit) : limit_(limit) {}
constexpr auto count() const -> size_t { return count_; }
FMT_CONSTEXPR auto limit(size_t size) -> size_t {
size_t n = limit_ > count_ ? limit_ - count_ : 0;
count_ += size;
return size < n ? size : n;
@@ -2224,7 +2224,7 @@ struct locale_ref {
template <typename Locale, FMT_ENABLE_IF(sizeof(Locale::collate) != 0)>
locale_ref(const Locale& loc);
explicit operator bool() const noexcept { return locale_ != nullptr; }
inline explicit operator bool() const noexcept { return locale_ != nullptr; }
#endif // FMT_USE_LOCALE
template <typename Locale> auto get() const -> Locale;
@@ -2599,7 +2599,7 @@ class context : private detail::locale_ref {
void operator=(const context&) = delete;
FMT_CONSTEXPR auto arg(int id) const -> format_arg { return args_.get(id); }
auto arg(string_view name) -> format_arg { return args_.get(name); }
inline auto arg(string_view name) -> format_arg { return args_.get(name); }
FMT_CONSTEXPR auto arg_id(string_view name) -> int {
return args_.get_id(name);
}
@@ -2608,7 +2608,7 @@ class context : private detail::locale_ref {
FMT_CONSTEXPR auto out() -> iterator { return out_; }
// Advances the begin iterator to `it`.
void advance_to(iterator) {}
FMT_CONSTEXPR void advance_to(iterator) {}
FMT_CONSTEXPR auto locale() -> detail::locale_ref { return *this; }
};