Skip to content

Conversation

@drebelsky
Copy link
Contributor

@drebelsky drebelsky commented Jan 8, 2026

Upgrade to C++20. Notes:

  • We need to upgrade autocheck for this because our current version uses std::result_of—I replaced it with the most recent release (and added the LICENSE file), although maybe we should replace it with a submodule instead

  • fmt::format requires a compile-time constant first parameter in 20 or to wrap in fmt::runtime—I wrapped the ones that prevent a compile, but most of those are std::strings that could probably be some variation of constexpr char[]s

  • for fmt to work on clang, it seems that we need to have a version starting from this commit. Otherwise, code like the following doesn't work

    auto out = std::vector<char>();
    fmt::format_to(std::back_inserter(out), FMT_STRING("{}"), 42);

    So, I bumped the versions of fmt and spdlog

    • With the newer version of spdlog, FMT_STRING without any template arguments no longer picks up the right overload, but the C++20 version seems to correctly do compile-time strings with out it, so I updated Logging.h to reflect this. One alternative is using the following macro, but I think it's probably cleaner to just remove the FMT_STRING usage in Logging.h
    #define ID(ARG) ARG
    #define LPAREN (
    #define RPAREN )
    /* Expands to `FMT_STRING(f), __VA_ARGS__` when __VA_ARGS__ is non-empty and `f`
     * otherwise (spdlog will not pick the proper overload if we only pass
     * FMT_STRING(f)) */
    #define LOG_FMT_STRING(f, ...) \
        ID(__VA_OPT__(FMT_STRING LPAREN) f __VA_OPT__(RPAREN)) \
        __VA_OPT__(, ) __VA_ARGS__
  • xdrpp on its current master doesn't work with C++20 because it will add a flag to enable C++11 features; the current change (in my fork) is the config only changes from the first commit on the cxx20 branch, but the output still isn't great. Also, note that doing the full first commit from the cxx20 (or the cxx20 branch) would require a bigger lift since it changes other parts of the codebase

    checking whether ccache clang++ -std=c++20 accepts -g... yes
    checking for ccache clang++ -std=c++20 option to enable C++11 features... -std=gnu++11
    checking dependency style of ccache clang++ -std=c++20 -std=gnu++11... gcc3
    checking whether ccache clang++ -std=c++20 -std=gnu++11 supports C++20 features by default... no
    checking whether ccache clang++ -std=c++20 -std=gnu++11 supports C++20 features with -std=gnu++20... yes
    

    This known issue is because autoconf adds a flag to enable C++11 features since C++20 isn't fully backwards compatible. Unfortunately, the patch is not in a released version of autoconf. Options include: using C++17 for xdrc compilation, using config/ax_cxx_compile_stdcxx.m4 (which that thread suggests is what GDB and GCC use instead of AC_PROG_CXX), or manually getting the patch.

@drebelsky
Copy link
Contributor Author

Looking at it now, I see we had some custom overrides in autocheck (e.g., using stellar:: prefixed random number generators), so I will re-evaluate that (maybe we should fork autocheck?).

@drebelsky drebelsky force-pushed the upgrade-to-cpp20 branch 2 times, most recently from 31a4a2c to 8b54014 Compare January 8, 2026 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant