catchorg / Catch2

A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
https://discord.gg/4CWS9zD
Boost Software License 1.0
18.51k stars 3.04k forks source link

GENERATOR doesn't allow use constants #2863

Closed subbota-a closed 5 months ago

subbota-a commented 5 months ago

Describe the bug I want to use constrants in the list of GENERATOR's values. gcc and clang doesn't compile code. https://godbolt.org/z/fxzqec7qT

Expected behavior Code is built

Reproduction steps See godbolt reference https://godbolt.org/z/fxzqec7qT

Platform information:

Additional context

#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>

TEST_CASE("1", ""){
    const auto x = 10;
    auto g = GENERATE(x, x+1, x+2);
    REQUIRE(g > 0);
}
In file included from <source>:2:
<source>: In lambda function:
<source>:6:23: error: 'x' is not captured
    6 |     auto g = GENERATE(x, x+1, x+2);
subbota-a commented 5 months ago

Use GENERATE_COPY