Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clara option agglomeration does not work as before anymore with gnu++23 #2787

Closed
AlexisWilke opened this issue Jan 1, 2024 · 3 comments
Closed
Labels

Comments

@AlexisWilke
Copy link

AlexisWilke commented Jan 1, 2024

Describe the bug

As per this documentation I can add my own options in this way:

auto cli
    = session.cli()           // Get Catch2's command line parser
    | Opt( height, "height" ) // bind variable to a new option, with a hint string
        ["-g"]["--height"]    // the option names it will respond to
        ("how high?");        // description string for the help output

That does not compile anymore in 3.5.1. It used to work in 3.5.0.

In file included from /home/snapwebsites/snapcpp/BUILD/Debug/dist/include/catch2/internal/catch_commandline.hpp:11,
                 from /home/snapwebsites/snapcpp/BUILD/Debug/dist/include/catch2/catch_session.hpp:11,
                 from /home/snapwebsites/snapcpp/BUILD/Debug/dist/include/catch2/snapcatch2.hpp:29,
                 from /home/snapwebsites/snapcpp/contrib/libexcept/tests/catch_main.h:23,
                 from /home/snapwebsites/snapcpp/contrib/libexcept/tests/catch_main.cpp:25:
/home/snapwebsites/snapcpp/BUILD/Debug/dist/include/catch2/internal/catch_clara.hpp: In instantiation of ‘Catch::Clara::Parser Catch::Clara::operator|(const Catch::Clara::Parser&, T&&) [with T = Catch::Clara::Opt]’:
/home/snapwebsites/snapcpp/contrib/libexcept/tests/catch_main.cpp:59:115:   required from here
/home/snapwebsites/snapcpp/BUILD/Debug/dist/include/catch2/internal/catch_clara.hpp:676:24: error: cannot bind non-const lvalue reference of type ‘Catch::Clara::Parser&’ to an rvalue of type ‘Catch::Clara::Parser’
  676 |                 return Parser( p ) |= CATCH_FORWARD(rhs);
      |                        ^~~~~~~~~~~
/home/snapwebsites/snapcpp/BUILD/Debug/dist/include/catch2/internal/catch_clara.hpp:667:48: note:   initializing argument 1 of ‘Catch::Clara::Parser& Catch::Clara::operator|=(Catch::Clara::Parser&, Catch::Clara::Opt&&)’
  667 |             friend Parser& operator|=( Parser& p, Opt&& opt ) {
      |                                        ~~~~~~~~^

which says that the value on the left side needs to be a variable.

I could change the code this way to make it compile:

auto cli = session.cli()           // Get Catch2's command line parser
cli |= Opt( height, "height" ) // bind variable to a new option, with a hint string
        ["-g"]["--height"]    // the option names it will respond to
        ("how high?");        // description string for the help output

Expected behavior

No error compiling code.

Reproduction steps

See above.

Platform information:

  • OS: Ubuntu 22.04.03
  • Compiler+version: g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
  • Catch version: v3.5.1

Additional context

I use the -std=g++23 command line option to compile my code.

@horenmar horenmar added the Bug label Jan 2, 2024
@horenmar
Copy link
Member

horenmar commented Jan 2, 2024

For the record, the exact standard does not have anything to do with the error, combining Parser const& with Opt would fail under any standard.

@johnhe4
Copy link

johnhe4 commented Jan 11, 2024

Thanks for the workaround @AlexisWilke. I have similar code that has been working for years but is now giving the same compilation error you posted, I'm guessing a brew upgrade was what triggered the issue for me. Separating the construction of the cli object from the operator |= seems better all around and compiles fine.

@johnhe4
Copy link

johnhe4 commented Jan 11, 2024

To add a bit more context, this page from the Android project is similarly incorrect and will mislead folks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants