Skip to content

Conversation

Kushagra1480
Copy link

Fixes #4124

Problem

When using FMT_COMPILE with named arguments, missing arguments do not cause compilation errors as they should.

fmt::format(FMT_COMPILE("{x}"));  // Should fail to compile, but doesn't

While regular fmt::format("{x}") correctly fails with a compilation error, FMT_COMPILE silently falls back to runtime handling, potentially causing runtime errors instead.

Solution

Added compile-time validation in the named argument handling path (around line 418 in compile.h). When a named argument is referenced but no arguments are provided (Args is type_list<>), the code now triggers a static_assert with a clear error message.

Changes

  • Added check for empty argument list when named argument lookup fails
  • Preserves existing behavior for valid runtime named arguments
  • Provides clear compile-time error message: "named argument referenced in format string but no arguments provided"

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR but it look like it only handles the case of no arguments provided which is not sufficient.

@Kushagra1480
Copy link
Author

Thanks for the PR but it look like it only handles the case of no arguments provided which is not sufficient.

No worries! I'll work on adding commits that address the other cases.

@vitaut
Copy link
Contributor

vitaut commented Oct 2, 2025

Closing for now but a new PR that adds a more general check rather than the empty argument case would be welcome.

@vitaut vitaut closed this Oct 2, 2025
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.

Missing named arguments do not cause compilation error when using FMT_COMPILE
2 participants