Skip to content

tests/infra: move to C++23 (std pins, g++-14 in CI, deducing this in test code)#228

Merged
cameroncuster merged 5 commits into
devfrom
cpp23-tests
Jul 7, 2026
Merged

tests/infra: move to C++23 (std pins, g++-14 in CI, deducing this in test code)#228
cameroncuster merged 5 commits into
devfrom
cpp23-tests

Conversation

@cameroncuster

@cameroncuster cameroncuster commented Jul 7, 2026

Copy link
Copy Markdown
Member

Moves the test/CI infrastructure from C++20 to C++23 and converts the recursive lambdas in test code to deducing this. Companion PR for the library conversion follows separately (#229, stacked on this one).

Why now

The 2025 Southeast USA regional judges on Kattis with g++-14 -O2 -std=gnu++23, and the SER contestant image ships g++ 14.2.0 — so our target contest environment is already C++23. Pinning the repo to the same standard means the hackpack is validated under the flags it will actually be compiled with.

Infrastructure changes

Every -std=c++20 pin bumped to -std=c++23:

  • .verify-helper/config.toml (verifier)
  • tests/.config/.gcc_compile_flags (compile_gcc)
  • tests/scripts/compile_clang.sh, clangtidy.sh, grep_clangformat_cppcheck.sh (cppcheck --std), compile_commented_snippets.sh
  • tests/Makefile help text
  • tests/.config/.clang-format: Standard: c++20Standard: Latest (clang-format has no c++23 enum value; Latest tracks the newest standard it knows)

CI toolchain: ubuntu-latest defaults to g++ 13.3, which has incomplete C++23 library support (no <generator>). The workflow now installs g++-14 and selects it via update-alternatives in:

  • the library_checker_aizu job (verifier uses plain g++)
  • the compile_gcc job
  • .github/actions/setup/action.yml (used by build_pdf → compile_commented_snippets, and the clang jobs' setup)

clang jobs already run clang-22, which is fully C++23-capable — flag bump only.

Test-code changes: deducing this (17 lambdas, 12 files)

Recursive lambdas in tests/library_checker_aizu_tests/ converted from the pass-self-explicitly idiom to C++23 deducing this:

// before
auto dfs = [&](auto&& self, int u, int p) -> void { ... self(self, v, u) ... };
dfs(dfs, root, -1);
// after
auto dfs = [&](this auto&& self, int u, int p) -> void { ... self(v, u) ... };
dfs(root, -1);

Justification: strictly shorter (drops the self parameter and the doubled argument at every call site), removes the most confusing idiom in the codebase, and avoids any chance of passing the wrong callable. No semantic change.

Files: cd_asserts.hpp, edge_cd_asserts.hpp, data_structures/permutation_tree, dsu/kruskal_tree_aizu, graphs/dijkstra_lib_checker, handmade_tests/{count_paths, dsu, seg_tree_midpoint}, trees/{edge_cd_count_paths_per_length, edge_cd_reroot_dp, shallowest_aizu_tree_height, shallowest_lib_checker_tree_path_composite}.

Not converted (GCC bug): the 4 lambdas in handmade_tests/functional_graph.test.cpp and trees/edge_cd_contour_range_{query,update}.test.cpp live inside struct constructors and access data members through the captured this. GCC 14/15 rejects member access inside a deducing-this lambda that captures the enclosing this (GCC PR113563, fixed in GCC 16) — CI's g++-14 fails on them, so they keep the pass-self idiom until the toolchain moves past the bug.

Validation

  • CI compile_gcc (g++-14) confirmed the member-function-lambda failures; those 3 files reverted, everything else passes
  • All modified .test.cpp files compile clean with g++ -std=c++23 -O2 -Wall -Wextra
  • clang-format --dry-run --Werror passes over the entire library + tests with the updated config

Note

World Finals is still documented as gnu++20 (though the WF25 Kattis mirror already used gnu++23). If the team advances, re-check that year's WF environment before relying on C++23-only features.

@cameroncuster cameroncuster merged commit d402f56 into dev Jul 7, 2026
10 checks passed
@cameroncuster cameroncuster deleted the cpp23-tests branch July 7, 2026 16:17
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.

2 participants