Skip to content

Possible undefined behavior with filter generator #3002

@Szapi

Description

@Szapi

Describe the bug
The following arrangement of generators behaves unexpectedly on different platforms with different compilations.

using secs = std::chrono::seconds;
using mins = std::chrono::minutes;

SCENARIO("Repro")
{
    using namespace Catch::Generators;
    const auto a = GENERATE(secs{ 0 }, secs{ 30 });

    const auto is_valid_b = [=] (const auto b) -> bool
    {
        return (a == secs{ 0 }) || (b <= a);
    };
    const auto b = GENERATE_COPY(
        filter(is_valid_b, values<secs>({ secs{ 10 }, secs{ 20 }, mins{ 1 }, mins{ 2 }, mins{ 5 }, mins{ 10 }, mins{ 30 } })));

    CHECK((a == secs{ 0 }) || (b <= a));
}

Amalgamated v3.7.1 is used everywhere.
With a local Windows 11 build, the generator seems to be working as expected, only 10s and 20s for 'b' is being generated when 'a' is not 0.
However, our Azure builds behave as if the filter was not there at all, both Win and Linux.
I did some debugging, but it is difficult to see what is going on with a release build.
The binaries from the server build do have the filter compiled, but when the filter's next() is invoked, it looks like as if the predicate lambda always captures 0 for the value of 'a', even if it is actually 30s.
Could not put a breakpoint inside the filter generators constructor, but manually stepping in Visual Studio, I could go into the constructor, and the local predicate seems to have the correct 30s value captured. When the filter's get() is called, it also shows the captured 30 in this->m_predicate.

I guess the big question is, is this even supposed to work?

Expected behavior
Filter should work regardless of compilation environment.

Reproduction steps
See the code above.

Platform information:

  • OS: Win 11
  • Compiler+version: MSVC (Visual Studio 17.14.5)
  • Catch version: v3.7.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions