Skip to content

Commit

Permalink
Don't explicitly delete copy ctor of dynamic_format_arg_store (#2664)
Browse files Browse the repository at this point in the history
* Don't explicitly delete copy ctor of dynamic_format_arg_store

Explicitly deleting the copy ctor causes the move constructor to not be
implicitly generated. This behaviour is different than what was in
v8.0.1 and causes code that relied on the move ctor of
dynamic_format_arg_store to break.

* Add test for dynamic_format_arg_store's move ctor

* include <memory>, don't use make_unique
  • Loading branch information
lucpelletier authored Dec 23, 2021
1 parent 664cd60 commit 7812813
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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
20 changes: 20 additions & 0 deletions test/args-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "fmt/args.h"

#include <memory>

#include "gtest/gtest.h"

TEST(args_test, basic) {
Expand Down Expand Up @@ -171,3 +173,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";

std::unique_ptr<fmt::dynamic_format_arg_store<fmt::format_context>>
store_uptr(new fmt::dynamic_format_arg_store<fmt::format_context>());
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);
}

0 comments on commit 7812813

Please sign in to comment.