jarro2783 / cxxopts

Lightweight C++ command line option parser
MIT License
4.16k stars 582 forks source link

cxxopts-3.2.0 breaks in c++20 mode: invalid operands to binary expression ('std::stringstream' (aka 'basic_stringstream<char>') and 'std::optional<bool>' #419

Closed yurivict closed 6 months ago

yurivict commented 6 months ago

log

FreeBSD 14.0

jarro2783 commented 6 months ago

Can you give me a minimal piece of code that reproduces this, and which compiler and other compile flags are you using?

yurivict commented 6 months ago

Here is the code that compiled before and doesn't compile now:

#include <cxxopts.hpp>

#include <optional>
#include <string>

int main(int argc, char** argv) {
        cxxopts::Options opts("appName", "0");

        std::optional<bool> minimized(false);
        bool enableDebugLogs = false;
        std::string torrents;

        opts.add_options(
        )("v,version", "display version information", cxxopts::value<bool>()->default_value("false")
        )("h,help", "display this help", cxxopts::value<bool>()->default_value("false")
        )("m,minimized", "start minimized in notification area", cxxopts::value(minimized)->default_value("false")
        )("d,debug-logs", "enable debug logs", cxxopts::value(enableDebugLogs)->implicit_value("true")
        )("torrents", "", cxxopts::value(torrents));
}

This project breaks.

clang-16.0.6 FreeBSD 14.0

yurivict commented 6 months ago

@jarro2783 Could you please fix this and make another release with the fix, because currently the FreeBSD port for Tremotesf2 is broken because of this problem.

jarro2783 commented 6 months ago

Thanks for the code to reproduce it, I'll see what I can do and make a new release.

jarro2783 commented 6 months ago

It breaks with ddc695e. It's a bit mysterious, I'm trying to work out what it was calling before that change.

jarro2783 commented 6 months ago

That was easy, turns out some functions were defined in the wrong order. I've just pushed a fix to a branch if you want to test it. I'll get it merged and tag a new version in a couple of hours.

yurivict commented 6 months ago

Sorry, I won't be able to test it. As long as this testcase builds - it probably should be fine.

frank-weinberg commented 5 months ago

I find a 3.2.1 tag with this fix but no release. Can the release be added?