Catch2
Catch2 copied to clipboard
GENERATE_COPY is unnecessary
There are three GENERATE macros defined:
https://github.com/catchorg/Catch2/blob/7b2e7d623b626ed2cae1d4b7f2b5480bdabbefd8/src/catch2/generators/catch_generators.hpp#L228-L239
Which all call Catch::Generators::generate:
https://github.com/catchorg/Catch2/blob/7b2e7d623b626ed2cae1d4b7f2b5480bdabbefd8/src/catch2/generators/catch_generators.hpp#L209-L223
Note that the lambda (generatorExpression) is unconditionally invoked immediately and not stored anywhere. That means that the only difference between: GENERATE_REF(a, b, c) and GENERATE_COPY(a, b, c) is that latter does an extra copy of its parameters. But it doesn't add any safety here - since the various generators take ownership anyway. It's purely overhead and users shouldn't use it.
This also calls into question the point of having GENERATE_REF and GENERATE both, since there doesn't seem to be potential harm in similarly defining:
#define GENERATE( ... ) \
Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \
CATCH_INTERNAL_LINEINFO, \
[&]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace)
So why is this issue neglected? Docs are still saying GENERATE_COPY and GENERATE_REF have more lifetime concerns than GENERATE, is it really necessary?