catchorg / catchorg/Catch2

GENERATE_COPY is unnecessary

Open
#2,512 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
21.5k
Forks
3.5k
Avg merge
3d 16h
Merged PRs (30d)
2

Description

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:

```cpp
#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)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.