Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Fix forwarding in SingleValueGenerator and generator creation

Fixes #1809
Commit
82baef62e2cc6766915e2278309e41cab514f53d
Author
Joe Burzinski ·
Committer
Martin Hořeňovský
Parents
0fbf4f3e152e

Files · Download .tar.gz

Changes

 src/catch2/catch_generators.hpp                           | 15 +++++++--------
 .../SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp  | 15 +++++++++++++++
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/catch2/catch_generators.hpp b/src/catch2/catch_generators.hpp
index de0b354d..86f02006 100644
--- a/src/catch2/catch_generators.hpp
+++ b/src/catch2/catch_generators.hpp
@@ -49,7 +49,6 @@ namespace Generators {
     class SingleValueGenerator final : public IGenerator<T> {
         T m_value;
     public:
-        SingleValueGenerator(T const& value) : m_value( value ) {}
         SingleValueGenerator(T&& value) : m_value(std::move(value)) {}
 
         T const& get() const override {
@@ -112,21 +111,21 @@ namespace Generators {
             m_generators.emplace_back(std::move(generator));
         }
         void populate(T&& val) {
-            m_generators.emplace_back(value(std::move(val)));
+            m_generators.emplace_back(value(std::forward<T>(val)));
         }
         template<typename U>
         void populate(U&& val) {
-            populate(T(std::move(val)));
+            populate(T(std::forward<U>(val)));
         }
         template<typename U, typename... Gs>
-        void populate(U&& valueOrGenerator, Gs... moreGenerators) {
+        void populate(U&& valueOrGenerator, Gs &&... moreGenerators) {
             populate(std::forward<U>(valueOrGenerator));
             populate(std::forward<Gs>(moreGenerators)...);
         }
 
     public:
         template <typename... Gs>
-        Generators(Gs... moreGenerators) {
+        Generators(Gs &&... moreGenerators) {
             m_generators.reserve(sizeof...(Gs));
             populate(std::forward<Gs>(moreGenerators)...);
         }
@@ -158,7 +157,7 @@ namespace Generators {
     struct as {};
 
     template<typename T, typename... Gs>
-    auto makeGenerators( GeneratorWrapper<T>&& generator, Gs... moreGenerators ) -> Generators<T> {
+    auto makeGenerators( GeneratorWrapper<T>&& generator, Gs &&... moreGenerators ) -> Generators<T> {
         return Generators<T>(std::move(generator), std::forward<Gs>(moreGenerators)...);
     }
     template<typename T>
@@ -166,11 +165,11 @@ namespace Generators {
         return Generators<T>(std::move(generator));
     }
     template<typename T, typename... Gs>
-    auto makeGenerators( T&& val, Gs... moreGenerators ) -> Generators<T> {
+    auto makeGenerators( T&& val, Gs &&... moreGenerators ) -> Generators<T> {
         return makeGenerators( value( std::forward<T>( val ) ), std::forward<Gs>( moreGenerators )... );
     }
     template<typename T, typename U, typename... Gs>
-    auto makeGenerators( as<T>, U&& val, Gs... moreGenerators ) -> Generators<T> {
+    auto makeGenerators( as<T>, U&& val, Gs &&... moreGenerators ) -> Generators<T> {
         return makeGenerators( value( T( std::forward<U>( val ) ) ), std::forward<Gs>( moreGenerators )... );
     }
 
diff --git a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp
index 17bc58e6..df5e036e 100644
--- a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp
@@ -315,6 +315,21 @@ TEST_CASE("GENERATE capture macros", "[generators][internals][approvals]") {
     REQUIRE(value == value2);
 }
 
+TEST_CASE("#1809 - GENERATE_COPY and SingleValueGenerator does not compile", "[generators][compilation][approvals]") {
+    // Verify Issue #1809 fix, only needs to compile.
+    auto a = GENERATE_COPY(1, 2);
+    (void)a;
+    auto b = GENERATE_COPY(as<long>{}, 1, 2);
+    (void)b;
+    int i = 1;
+    int j = 2;
+    auto c = GENERATE_COPY(i, j);
+    (void)c;
+    auto d = GENERATE_COPY(as<long>{}, i, j);
+    (void)d;
+    SUCCEED();
+}
+
 TEST_CASE("Multiple random generators in one test case output different values", "[generators][internals][approvals]") {
     SECTION("Integer") {
         auto random1 = Catch::Generators::random(0, 1000);