Skip to content

Commit 5a84635

Browse files
committed
Document caveat of string builder tests regarding copy/move
1 parent fb58993 commit 5a84635

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tests/conversiontests.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ struct StringThatDoesNotLikeToBeCopiedOrMoved : public std::string {
418418
: std::string(value)
419419
{
420420
}
421+
// delete copy and move c'tor so if argsToString() would invoke one it would be a compile time error
422+
// caveat: argsToString() might still construct an std::string() unnoticed.
421423
[[noreturn]] StringThatDoesNotLikeToBeCopiedOrMoved(const StringThatDoesNotLikeToBeCopiedOrMoved &other) = delete;
422424
[[noreturn]] StringThatDoesNotLikeToBeCopiedOrMoved(StringThatDoesNotLikeToBeCopiedOrMoved &&other) = delete;
423425
};
@@ -468,9 +470,8 @@ void ConversionTests::testStringBuilder()
468470
CPPUNIT_ASSERT_EQUAL_MESSAGE("using string_view", "foobar123"s, "foo"sv % "bar"sv + 123);
469471

470472
// check that for the internal tuple construction no copies are made
471-
StringThatDoesNotLikeToBeCopiedOrMoved str(" happen ");
472-
const StringThatDoesNotLikeToBeCopiedOrMoved str2("for this");
473-
// Both deleted so becomes a compilation test rather than a runtime one
473+
auto str = StringThatDoesNotLikeToBeCopiedOrMoved(" happen ");
474+
const auto str2 = StringThatDoesNotLikeToBeCopiedOrMoved("for this");
474475
CPPUNIT_ASSERT_EQUAL("no copy/move should happen for this!"s,
475476
argsToString(StringThatDoesNotLikeToBeCopiedOrMoved("no copy/move should"), str, str2, StringThatDoesNotLikeToBeCopiedOrMoved("!")));
476477
}

0 commit comments

Comments
 (0)