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

Don't explicitly delete copy ctor of dynamic_format_arg_store #2664

Merged
merged 3 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 0 additions & 3 deletions include/fmt/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ class dynamic_format_arg_store
public:
constexpr dynamic_format_arg_store() = default;

constexpr dynamic_format_arg_store(
const dynamic_format_arg_store<Context>& store) = delete;

/**
\rst
Adds an argument into the dynamic store for later passing to a formatting
Expand Down
18 changes: 18 additions & 0 deletions test/args-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,21 @@ TEST(args_test, throw_on_copy) {
}
EXPECT_EQ(fmt::vformat("{}", store), "foo");
}

TEST(args_test, move_constructor) {
const int test_integer = 42;
const char* const test_c_string = "foo";

auto store_uptr =
std::make_unique<fmt::dynamic_format_arg_store<fmt::format_context>>();
Copy link
Contributor

Choose a reason for hiding this comment

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

std::make_unique - C++14+

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

store_uptr->push_back(test_integer);
store_uptr->push_back(std::string(test_c_string));
store_uptr->push_back(fmt::arg("a1", test_c_string));

fmt::dynamic_format_arg_store<fmt::format_context> moved_store(
std::move(*store_uptr));
store_uptr.reset();
EXPECT_EQ(
fmt::vformat("{} {} {a1}", moved_store),
std::to_string(test_integer) + " " + test_c_string + " " + test_c_string);
}