Skip to content

Fix nvcc C++17 compile with std::back_insert_iterator (fixes #5046) - #5049

Open
Tyagiquamar wants to merge 1 commit into
fmtlib:mainfrom
Tyagiquamar:fix/5046-nvcc-back-inserter-cxx17
Open

Tyagiquamar wants to merge 1 commit into
fmtlib:mainfrom
Tyagiquamar:fix/5046-nvcc-back-inserter-cxx17

Conversation

@Tyagiquamar

Copy link
Copy Markdown
Contributor

Summary

  • Fixes a fmt 12.2 regression where nvcc in C++17 mode fails to compile fmt::format_to(std::back_inserter(...), ...).
  • Restores FMT_CONSTEXPR20 on detail::get_container() and its local accessor constructor, matching pre-12.2 behavior under C++17 (where back_insert_iterator is not a literal type).
  • Extends the optional CUDA smoke test to cover format_to with std::back_inserter.

Root cause

Commit e99ef3f ("Relax constexpr") marked get_container and accessor as constexpr in all language modes. Under C++17, libstdc++'s std::back_insert_iterator constructor is not constexpr, so nvcc's EDG front end rejects the accessor base constructor even though GCC accepts the unused template specialization (see #5046).

Solution

In include/fmt/core.h, use FMT_CONSTEXPR20 for get_container and accessor, so these functions are only constexpr when the library enables C++20 constexpr extensions (same approach as fmt 12.1.0).

Test plan

  • Regression coverage in test/cuda-test/cuda-cpp14.cu and test/cuda-test/cpp14.cc (format_to + back_inserter).
  • Local run blocked here: Docker Desktop API returned 500 during gcc:14-bookworm builds on this machine.
  • CI (fork PR): linux / windows / macos workflows; optional cuda-test when FMT_CUDA_TEST is enabled.

Fixes #5046.

)

Restore FMT_CONSTEXPR20 on detail::get_container and its accessor so
nvcc in C++17 mode does not diagnose a constexpr parameter of nonliteral
type. Extend the CUDA smoke test to format via back_inserter.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Tyagiquamar
Tyagiquamar requested a review from vitaut as a code owner November 30, 2026 08:53
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.

12.2: nvcc rejects constexpr get_container() for std::back_insert_iterator in C++17 (regression from e99ef3f9)

1 participant