Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Formatting long with FMT_BUILTIN_TYPES=0 #4394

@montekarlos

Description

@montekarlos

Consider the following code sample using fmtlib v11.1.4 or master

#define FMT_BUILTIN_TYPES 0

#include <cstdint>
#include <fmt/format.h>

int main() {
    long n(1234);
    fmt::print("1234!={}", n);    
}

The expected output of this is 1234!=1234 however when built and run using FMT_BUILTIN_TYPES=0 the results are 1234!=536895556 (your results will vary)

Note that changing long to int will resolve this

I'm hitting this issue on non-eabi (defines int32_t as long) but I can also create on x64 MSVC.

My understand is of this is that during argument processing custom.value and custom.format are set, but then basic_format_args::type detects as detail::type::int_type so then during formatting (visit) the wrong member of the union is used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions