Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

presentation_type c accepted in combination with bool #3726

Closed
ingo-loehken opened this issue Nov 24, 2023 · 1 comment · Fixed by #3734
Closed

presentation_type c accepted in combination with bool #3726

ingo-loehken opened this issue Nov 24, 2023 · 1 comment · Fixed by #3734

Comments

@ingo-loehken
Copy link

ingo-loehken commented Nov 24, 2023

While applying massive random tests with generated format-specs, it turned out that the c presentation-type is allowed for bool.

    std::string_view constexpr formatString{"{:X<#9c}"}; // invalid format string
    std::cout << fmt::format(formatString, false) << std::endl; // accepted, compile error expected
    std::cout << std::format(formatString, false) << std::endl; // rejected, compiler error as expected

godbolt

While writing for false the value is missing

    std::string_view constexpr formatString{"{:X<#2c}"};
    auto const s1{fmt::format(formatString, false)};
    std::cout << s1 << std::endl; // prints "X"

godbolt

for true the output seems to include uninitialized memory (unprintable chars)

    std::string_view constexpr formatString{"{:X<#2c}"};
    auto const s1{fmt::format(formatString, false)};
    std::cout << s1 << std::endl; // prints "?X", where ? is an unprintable char

godbolt

@vitaut
Copy link
Contributor

vitaut commented Nov 24, 2023

The output is \0 or \1, not uninitialized, but I agree that we should forbid this as std::format does. A PR would be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants