Skip to content

FMT_STRING consteval error with Apple clang 21 (Xcode 26.4) #4740

@turban

Description

@turban

Compiling the fmt pod via CocoaPods on Xcode 26.4 (Apple clang 21.0.0, clang-2100.0.123.102) fails with:

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

Errors appear in fmt/include/fmt/format-inl.h at lines 59, 60, 1387, 1391, and 1394 — all call sites of FMT_STRING(...).

Environment

  • Xcode 26.4, build version 17E192
  • Apple clang 21.0.0 (clang-2100.0.123.102)
  • fmt version: bundled with @maplibre/maplibre-react-native via CocoaPods

Root cause

base.h sets FMT_USE_CONSTEVAL 1 for Apple clang ≥ 14 (__apple_build_version__ >= 14000029L), enabling the consteval constructor in basic_format_string. Apple clang 21 is stricter about requiring consteval call sites to themselves be constant expressions, so the FMT_STRING(...) usages in format-inl.h — which are not constant expressions — are rejected.

Workaround

Patch base.h to treat all Apple clang versions the same as < 14 (i.e. FMT_USE_CONSTEVAL 0):

-#elif defined(__apple_build_version__) && __apple_build_version__ < 14000029L
+#elif defined(__apple_build_version__)
 #  define FMT_USE_CONSTEVAL 0  // consteval is broken in Apple clang

Prior art

PR #4703 proposed a fix for this (adding a new threshold for clang 21+) but was closed without merging and without explanation. This issue is a request to reconsider that fix or apply an alternative.

Note: passing -DFMT_CONSTEVAL= or -DFMT_USE_CONSTEVAL=0 via compiler flags does not work, because base.h unconditionally redefines both macros through its own #if/#elif chain, overwriting any -D flag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions