Skip to content

Disable consteval on Apple clang 21#4703

Closed
lapfelix wants to merge 4 commits intofmtlib:masterfrom
lapfelix:codex/xcode-26-4-beta-2-apple-clang-21
Closed

Disable consteval on Apple clang 21#4703
lapfelix wants to merge 4 commits intofmtlib:masterfrom
lapfelix:codex/xcode-26-4-beta-2-apple-clang-21

Conversation

@lapfelix
Copy link
Copy Markdown

@lapfelix lapfelix commented Mar 6, 2026

Summary

Disable the FMT_CONSTEVAL path on Apple clang 21.

Context

While building Transit's vendored copy of fmt with Xcode 26.4 beta 2 (Apple clang 21.0.0 / clang-2100.0.121.2), clang rejects several FMT_STRING(...) call sites with errors like:

error: call to consteval function 'fmt::basic_format_string<...>' is not a constant expression

The first failure I hit was in format-inl.h while compiling a downstream translation unit that includes fmt/core.h.

Change

This introduces FMT_USE_CONSTEVAL and disables it for Apple clang 21+, leaving the existing FMT_CONSTEVAL path unchanged for other toolchains.

Verification

Built the affected downstream target successfully after this change:

xcodebuild -project Submodules/transitLib/xcode_build/transitLib.xcodeproj \
  -scheme bgtfs \
  -destination 'generic/platform=iOS Simulator' \
  build

saraedum and others added 4 commits January 3, 2024 10:09
Fixes #3785.

the write_console symbol has changed from 10.1 to 10.2. Here we restore
the symbol as introduced in 10.1.
@lapfelix lapfelix closed this Mar 6, 2026
@lakshit-acv
Copy link
Copy Markdown

We can possibly give reason or some explanation as to why the PR has been closed. Helps a lot towards getting more context. Thanks !

@turban
Copy link
Copy Markdown

turban commented Apr 10, 2026

We're hitting the same issue in a React Native / Expo project building with Xcode 16 (Apple clang 16, not quite clang 21 but the same failure mode). The errors are identical — call to consteval function '...basic_format_string...' is not a constant expression in format-inl.h.

We worked around it by patching base.h in a CocoaPods post_install hook, removing the < 14000029L version threshold so that all Apple clang versions take the FMT_USE_CONSTEVAL 0 path:

content = content.gsub(
  'defined(__apple_build_version__) && __apple_build_version__ < 14000029L',
  'defined(__apple_build_version__)'
)

The approach in this PR (adding a new threshold for clang 21+) seems like the cleaner upstream fix. Would the maintainers consider reopening or a follow-up PR? The workaround burden is falling on every downstream project that builds fmt via CocoaPods with a recent Xcode.

@vitaut
Copy link
Copy Markdown
Contributor

vitaut commented Apr 10, 2026

The error "not a constant expression" usually indicates that the format string is invalid. You'll need to provide a repro to demonstrate that there is an actual issue with consteval in clang (which is unlikely).

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.

5 participants