Build fixes

This commit is contained in:
vsol 2020-03-13 10:00:23 +03:00
parent 435133426e
commit 90219a772b
2 changed files with 18 additions and 15 deletions

View File

@ -11,13 +11,6 @@
#include "core.h" #include "core.h"
#if (defined(FMT_HAS_VARIANT) || __cplusplus >= 201703L)
# include <variant>
# ifndef FMT_HAS_VARIANT
# define FMT_HAS_VARIANT
# endif
#endif
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
namespace internal { namespace internal {
@ -61,18 +54,23 @@ template <typename T, typename Context>
using need_dyn_copy_t = typename need_dyn_copy<T, Context>::type; using need_dyn_copy_t = typename need_dyn_copy<T, Context>::type;
class dyn_arg_storage { class dyn_arg_storage {
// Workaround clang's -Wweak-vtables. For templates (unlike regular classes
// doesn't complain about inability to deduce translation unit to place vtable
// So dyn_arg_node_base is made a fake template
template<typename = void>
struct dyn_arg_node_base { struct dyn_arg_node_base {
virtual ~dyn_arg_node_base() = default; virtual ~dyn_arg_node_base() = default;
std::unique_ptr<dyn_arg_node_base> next_; std::unique_ptr<dyn_arg_node_base> next_;
}; };
template<typename T> template<typename T>
struct dyn_arg_node : dyn_arg_node_base { struct dyn_arg_node : dyn_arg_node_base<> {
T value_; T value_;
FMT_CONSTEXPR explicit dyn_arg_node(T&& arg) : value_{arg}{} FMT_CONSTEXPR explicit dyn_arg_node(T&& arg) : value_{arg}{}
}; };
std::unique_ptr<dyn_arg_node_base> head_{nullptr}; std::unique_ptr<dyn_arg_node_base<>> head_{nullptr};
public: public:
dyn_arg_storage() = default; dyn_arg_storage() = default;
@ -84,8 +82,8 @@ public:
template<typename T> template<typename T>
const T& emplace_front(T&& val) { const T& emplace_front(T&& val) {
auto node{new dyn_arg_node<T>{std::forward<T>(val)}}; auto node = new dyn_arg_node<T>{std::forward<T>(val)};
std::unique_ptr<dyn_arg_node_base> ptr{node}; std::unique_ptr<dyn_arg_node_base<>> ptr{node};
swap(ptr, head_); swap(ptr, head_);
head_->next_ = std::move(ptr); head_->next_ = std::move(ptr);
return node->value_; return node->value_;

View File

@ -31,18 +31,18 @@ TEST(FormatDynArgsTest, StringsAndRefs) {
EXPECT_EQ("1234567890 and X234567890 and X234567890", result); EXPECT_EQ("1234567890 and X234567890 and X234567890", result);
} }
struct Custom { struct custom_type {
int i{0}; int i{0};
}; };
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
template <> struct formatter<Custom> { template <> struct formatter<custom_type> {
auto parse(format_parse_context& ctx) const -> decltype(ctx.begin()) { auto parse(format_parse_context& ctx) const -> decltype(ctx.begin()) {
return ctx.begin(); return ctx.begin();
} }
template <typename FormatContext> template <typename FormatContext>
auto format(const Custom& p, FormatContext& ctx) -> decltype(format_to( auto format(const custom_type& p, FormatContext& ctx) -> decltype(format_to(
ctx.out(), std::declval<typename FormatContext::char_type const*>())) { ctx.out(), std::declval<typename FormatContext::char_type const*>())) {
return format_to(ctx.out(), "cust={}", p.i); return format_to(ctx.out(), "cust={}", p.i);
} }
@ -50,8 +50,13 @@ template <> struct formatter<Custom> {
FMT_END_NAMESPACE FMT_END_NAMESPACE
TEST(FormatDynArgsTest, CustomFormat) { TEST(FormatDynArgsTest, CustomFormat) {
using context = fmt::format_context;
fmt::dynamic_format_arg_store<fmt::format_context> store; fmt::dynamic_format_arg_store<fmt::format_context> store;
Custom c{}; static_assert(fmt::internal::need_dyn_copy_t<custom_type, context>::value, "");
static_assert(
fmt::internal::mapped_type_constant<custom_type, context>::value ==
fmt::internal::type::custom_type, "");
custom_type c{};
store.push_back(c); store.push_back(c);
++c.i; ++c.i;
store.push_back(c); store.push_back(c);