-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[docs][clang-tidy] Correct StrictMode example in modernize-use-std-print #108805
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
Conversation
Updated the example in the StrictMode section of the clang-tidy check modernize-use-std-print. The previous example incorrectly swapped the cast of signed and unsigned integers. Specifically: The signed integer i was being cast to unsigned int, and The unsigned integer u was being cast to int. This correction ensures that the behavior of std::print with StrictMode enabled matches that of printf, by reversing the casts to maintain the correct signedness. Issue Refference It solves #llvm#101397
@llvm/pr-subscribers-clang-tidy Author: Mainak Sil (MainakSil) ChangesUpdated the example in the The previous example incorrectly swapped the cast of signed and unsigned integers. Specifically:
This correction ensures that the behavior of Issue Refference Full diff: https://github.com/llvm/llvm-project/pull/108805.diff 1 Files Affected:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
index 59bb722e2c24fc..a825cd7432a57d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
@@ -109,7 +109,7 @@ Options
.. code-block:: c++
- std::print("{} {}\n", static_cast<unsigned int>(i), static_cast<int>(u));
+ std::print("{} {}\n", static_cast<int>(u), static_cast<unsigned int>(i));
to ensure that the output will continue to be the unsigned representation
of `-42` and the signed representation of `0xffffffff` (often
|
@llvm/pr-subscribers-clang-tools-extra Author: Mainak Sil (MainakSil) ChangesUpdated the example in the The previous example incorrectly swapped the cast of signed and unsigned integers. Specifically:
This correction ensures that the behavior of Issue Refference Full diff: https://github.com/llvm/llvm-project/pull/108805.diff 1 Files Affected:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
index 59bb722e2c24fc..a825cd7432a57d 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
@@ -109,7 +109,7 @@ Options
.. code-block:: c++
- std::print("{} {}\n", static_cast<unsigned int>(i), static_cast<int>(u));
+ std::print("{} {}\n", static_cast<int>(u), static_cast<unsigned int>(i));
to ensure that the output will continue to be the unsigned representation
of `-42` and the signed representation of `0xffffffff` (often
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the example should be:
printf("%u %d\n", i, u); // Change here.
// transforms to:
std::println("{} {}", static_cast<unsigned int>(i), static_cast<int>(u)); // No change here.
@@ -109,7 +109,7 @@ Options | |||
|
|||
.. code-block:: c++ | |||
|
|||
std::print("{} {}\n", static_cast<unsigned int>(i), static_cast<int>(u)); | |||
std::print("{} {}\n", static_cast<int>(u), static_cast<unsigned int>(i)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The arguments shouldn't be swapped, I think the initial code block above must swap the %d
and %u
specifier for this example to make sense.
cc @mikecrowe |
Please check now. |
Thanks for fixing this @MainakSil. I wasn't aware of the bug report until now. @nicovank is correct that only the format string needs to change as I got the format specifiers the wrong way round originally. Thanks for adding me to this change. I copied the same mistake to Thanks. |
Thanks for pointing that out, @mikecrowe! I've gone ahead and fixed the same mistake in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for fixing this.
Please merge it if it looks good to you guys... |
Updated the example in the
StrictMode
section of the clang-tidy checkmodernize-use-std-print
.The previous example incorrectly swapped the cast of signed and unsigned integers. Specifically:
i
was being cast tounsigned int
, andu
was being cast toint
.This correction ensures that the behavior of
std::print
withStrictMode
enabled matches that ofprintf
, by reversing the casts to maintain the correct signedness.Issue Refference
It solves #101397