Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp
diff options
context:
space:
mode:
authorSzapi2025-08-23 21:55:38 +0200
committerGitHub2025-08-23 21:55:38 +0200
commit85c4bad86b0bd29b6d2f5aa270401c0a642d53b1 (patch)
tree9f905f9cb9b2a0000760dc58880e956db2acfddd /tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp
parent582200a1f8ddd6f435d1264668c7074121c2636c (diff)
downloadcatch3-85c4bad86b0bd29b6d2f5aa270401c0a642d53b1.tar.gz
Forbid deducing reference types for m_predicate in FilterGenerator (#3005)
Forbid deducing reference types for m_predicate in FilterGenerator to prevent dangling references. This is needed for out-of-line predicates to work correctly instead of undefined behavior or crashes. --------- Co-authored-by: Tek Mate <mate.tek@evosoft.com>
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp')
-rw-r--r--tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp
index 14c90114..c044547d 100644
--- a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp
@@ -85,6 +85,19 @@ TEST_CASE("Generators internals", "[generators][internals]") {
filter([](int) { return false; }, values({ 1, 2, 3 })),
Catch::GeneratorException);
}
+
+ // Non-trivial usage
+ SECTION("Out-of-line predicates are copied into the generator") {
+ auto evilNumber = Catch::Detail::make_unique<int>(2);
+ auto gen = [&]{
+ const auto predicate = [&](int i) { return i != *evilNumber; };
+ return filter(predicate, values({ 2, 1, 2, 3, 2, 2 }));
+ }();
+ REQUIRE(gen.get() == 1);
+ REQUIRE(gen.next());
+ REQUIRE(gen.get() == 3);
+ REQUIRE_FALSE(gen.next());
+ }
}
SECTION("Take generator") {
SECTION("Take less") {