Skip to content

Commit

Permalink
Disable broken copy ctor of dynamic_format_arg_store
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Dec 18, 2021
1 parent 659de77 commit be51ee1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 32 deletions.
9 changes: 1 addition & 8 deletions include/fmt/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,7 @@ class dynamic_format_arg_store
constexpr dynamic_format_arg_store() = default;

constexpr dynamic_format_arg_store(
const dynamic_format_arg_store<Context>& store)
:
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
basic_format_args<Context>(),
#endif
data_(store.data_),
named_info_(store.named_info_) {
}
const dynamic_format_arg_store<Context>& store) = delete;

/**
\rst
Expand Down
35 changes: 11 additions & 24 deletions test/args-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "gtest/gtest.h"

TEST(args_test, basic) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
fmt::dynamic_format_arg_store<fmt::format_context> store;
store.push_back(42);
store.push_back("abc1");
store.push_back(1.5f);
Expand All @@ -19,7 +19,7 @@ TEST(args_test, basic) {

TEST(args_test, strings_and_refs) {
// Unfortunately the tests are compiled with old ABI so strings use COW.
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
fmt::dynamic_format_arg_store<fmt::format_context> store;
char str[] = "1234567890";
store.push_back(str);
store.push_back(std::cref(str));
Expand Down Expand Up @@ -48,7 +48,7 @@ template <> struct formatter<custom_type> {
FMT_END_NAMESPACE

TEST(args_test, custom_format) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
fmt::dynamic_format_arg_store<fmt::format_context> store;
auto c = custom_type();
store.push_back(c);
++c.i;
Expand Down Expand Up @@ -77,21 +77,21 @@ template <> struct formatter<to_stringable> {
FMT_END_NAMESPACE

TEST(args_test, to_string_and_formatter) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
fmt::dynamic_format_arg_store<fmt::format_context> store;
auto s = to_stringable();
store.push_back(s);
store.push_back(std::cref(s));
fmt::vformat("", store);
}

TEST(args_test, named_int) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
fmt::dynamic_format_arg_store<fmt::format_context> store;
store.push_back(fmt::arg("a1", 42));
EXPECT_EQ("42", fmt::vformat("{a1}", store));
}

TEST(args_test, named_strings) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
fmt::dynamic_format_arg_store<fmt::format_context> store;
char str[] = "1234567890";
store.push_back(fmt::arg("a1", str));
store.push_back(fmt::arg("a2", std::cref(str)));
Expand All @@ -100,15 +100,15 @@ TEST(args_test, named_strings) {
}

TEST(args_test, named_arg_by_ref) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
fmt::dynamic_format_arg_store<fmt::format_context> store;
char band[] = "Rolling Stones";
store.push_back(fmt::arg("band", std::cref(band)));
band[9] = 'c'; // Changing band affects the output.
EXPECT_EQ(fmt::vformat("{band}", store), "Rolling Scones");
}

TEST(args_test, named_custom_format) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
fmt::dynamic_format_arg_store<fmt::format_context> store;
auto c = custom_type();
store.push_back(fmt::arg("c1", c));
++c.i;
Expand All @@ -121,7 +121,7 @@ TEST(args_test, named_custom_format) {
}

TEST(args_test, clear) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
fmt::dynamic_format_arg_store<fmt::format_context> store;
store.push_back(42);

auto result = fmt::vformat("{}", store);
Expand All @@ -138,7 +138,7 @@ TEST(args_test, clear) {
}

TEST(args_test, reserve) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
fmt::dynamic_format_arg_store<fmt::format_context> store;
store.reserve(2, 1);
store.push_back(1.5f);
store.push_back(fmt::arg("a1", 42));
Expand All @@ -163,24 +163,11 @@ template <> struct formatter<copy_throwable> {
FMT_END_NAMESPACE

TEST(args_test, throw_on_copy) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
fmt::dynamic_format_arg_store<fmt::format_context> store;
store.push_back(std::string("foo"));
try {
store.push_back(copy_throwable());
} catch (...) {
}
EXPECT_EQ(fmt::vformat("{}", store), "foo");
}

TEST(args_test, copy_constructor) {
auto store = fmt::dynamic_format_arg_store<fmt::format_context>();
store.push_back(fmt::arg("test1", "value1"));
store.push_back(fmt::arg("test2", "value2"));
store.push_back(fmt::arg("test3", "value3"));

auto store2 = store;
store2.push_back(fmt::arg("test4", "value4"));

auto result = fmt::vformat("{test1} {test2} {test3} {test4}", store2);
EXPECT_EQ(result, "value1 value2 value3 value4");
}

0 comments on commit be51ee1

Please sign in to comment.