Skip to content

[docs][clang-tidy] modernize-use-std-print document for StrictMode seems incorrect #101397

@another-pjohnson

Description

@another-pjohnson
StrictMode[¶](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-std-print.html#cmdoption-arg-StrictMode)
When true, the check will add casts when converting from variadic functions like printf and printing signed or unsigned integer types (including fixed-width integer types from <cstdint>, ptrdiff_t, size_t and ssize_t) as the opposite signedness to ensure that the output matches that of printf. This does not apply when converting from non-variadic functions such as absl::PrintF and fmt::printf. For example, with StrictMode enabled:

int i = -42;
unsigned int u = 0xffffffff;
printf("%d %u\n", i, u);
would be converted to:

std::print("{} {}\n", static_cast<unsigned int>(i), static_cast<int>(u));
to ensure that the output will continue to be the unsigned representation of -42 and the signed representation of 0xffffffff (often 4294967254 and -1 respectively.) When false (which is the default), these casts will not be added which may cause a change in the output.

This logic doesn't make sense, I think the example was supposed to swap the order of i and u.

See the compiler explorer with this exact example:
https://godbolt.org/z/czxjW3s6b

Results are

-42 4294967295 (printf)
4294967254 -1 (std::print)

In StrictMode, i would expect you want to maintain the exact same value printed out unless I am missing something.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions