Skip to content

fix: allow zero-padding for pointer formatting (fixes #2025)#4809

Open
Muptezel58 wants to merge 1 commit into
fmtlib:mainfrom
Muptezel58:fix/pointer-zero-padding
Open

fix: allow zero-padding for pointer formatting (fixes #2025)#4809
Muptezel58 wants to merge 1 commit into
fmtlib:mainfrom
Muptezel58:fix/pointer-zero-padding

Conversation

@Muptezel58

Copy link
Copy Markdown

Problem

Using the 0 (zero-pad) flag with pointer arguments currently raises:
format specifier requires numeric argument

Root Cause

In include/fmt/base.h, the case '0': handler only allows
is_arithmetic_type, which excludes pointer_type.

Fix

Extended the check to also permit pointer_type:

// Before:
if (!is_arithmetic_type(arg_type))

// After:
if (!is_arithmetic_type(arg_type) && !in(arg_type, pointer_set))

Test

void* ptr = (void*)0x2993;
fmt::format("{:018}", ptr); // Previously threw, now returns: 000000000000x2993

Closes #2025

Previously, using '0' flag with pointer arguments raised:
  'format specifier requires numeric argument'

This patch extends the zero-flag check to also allow pointer_type,
enabling zero-padded pointer output such as fmt::format("{:018}", ptr).
@Muptezel58 Muptezel58 requested a review from vitaut as a code owner June 15, 2026 09:44
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.

Support zero-padding with pointers

1 participant