Skip to content

Conversation

@drebelsky
Copy link
Contributor

@drebelsky drebelsky commented Jan 8, 2026

Upgrade to C++20. Notes:

  • autocheck uses std::result_of (deprecated in 17, removed in 20)—I replaced just the use of that since we seem to have a de-facto in-tree fork of autocheck (e.g., we reference stellar::).

  • fmt::format requires a either a compile-time constant first parameter in 20 or a fmt::runtime call.

  • 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 needs to get updated for two reasons.

    1. On its current master, we end up trying to build using C++14, but it should be at least 17. Bumping to 20 (or 17) we get some extra flags1

      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
      
    2. Because of the spaceship operator, at the very least, we need operator<=> defined for xdr::pointer since it inherits from std::unique_ptr which defines <=>, meaning that without the overload, e.g., std::vector<xdr::pointer<int>> comparisons no longer work properly (they go back to comparing by address instead of value).

    There is the cxx20 branch, but it doesn't have the most recent 5 commits from the master branch (which we rely on in core). Additionally, it seems to be somewhat buggy (e.g., tests/marshal.cc doesn't pass). So, for the purposes of this PR, I think it's probably easiest to just bump to 20 and add operator<=> for xdr data types.

  • Small change, but renamed the constructor in the header file for ScopedLedgerEntry since ScopedLedgerEntry<T> isn't technically valid since DR 2237 was adopted in C++20 (link).

Footnotes

  1. Due to a known issue: autoconf adds a flag to enable C++11 features since C++20 isn't fully backwards compatible. Unfortunately, the patch to fix this behavior is not in a released version of autoconf

@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 3 times, most recently from 8b54014 to 65b6f30 Compare January 12, 2026 18:53
@drebelsky
Copy link
Contributor Author

drebelsky commented Jan 21, 2026

Looks like this failed last time because of xdrpp building on C++14, bumping to the commit introduced in this pr

@drebelsky
Copy link
Contributor Author

The test case "LedgerTxnRoot prefetch classic entries" fails because vectors of xdr::pointers break (due to the spaceship operator overloads) in C++20, so I will work on merging the cxx20 branch with master in xdrpp.

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