[clang-tools-extra] [docs][clang-tidy] Correct StrictMode example in modernize-use-std-print (PR #108805)
Mainak Sil via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 16 19:37:32 PDT 2024
https://github.com/MainakSil updated https://github.com/llvm/llvm-project/pull/108805
>From 20b262e9954ec1505b1be4ea3cc362b2a9955bb9 Mon Sep 17 00:00:00 2001
From: Mainak Sil <mainaksil0 at gmail.com>
Date: Sun, 15 Sep 2024 22:03:43 +0530
Subject: [PATCH 1/4] [docs][clang-tidy] Correct StrictMode example in
modernize-use-std-print
---
.../docs/clang-tidy/checks/modernize/use-std-print.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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
>From e64700266ecc08b23f88415036c45177a03c40c2 Mon Sep 17 00:00:00 2001
From: Mainak Sil <mainaksil0 at gmail.com>
Date: Mon, 16 Sep 2024 14:41:49 +0530
Subject: [PATCH 2/4] [docs][clang-tidy] Correct StrictMode example in
modernize-use-std-print
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
>From 000fa0b26c087c17b23da57d02422816c00bcbd1 Mon Sep 17 00:00:00 2001
From: Mainak Sil <mainaksil0 at gmail.com>
Date: Mon, 16 Sep 2024 22:31:55 +0530
Subject: [PATCH 3/4] Update use-std-print.rst
---
.../docs/clang-tidy/checks/modernize/use-std-print.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
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 a825cd7432a57d..e70402ad8b3341 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
@@ -103,13 +103,13 @@ Options
int i = -42;
unsigned int u = 0xffffffff;
- printf("%d %u\n", i, u);
+ printf("%u %d\n", i, u);
would be converted to:
.. code-block:: c++
- std::print("{} {}\n", static_cast<int>(u), static_cast<unsigned int>(i));
+ 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
>From b40f7a9fe5964c9436e1bfd28b2dbe91cbcc65ae Mon Sep 17 00:00:00 2001
From: Mainak Sil <mainaksil0 at gmail.com>
Date: Tue, 17 Sep 2024 08:07:23 +0530
Subject: [PATCH 4/4] Update printf specifiers in StrictMode example
---
.../docs/clang-tidy/checks/modernize/use-std-format.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
index 1ec753ef090de1..b88fde5162e28c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
@@ -43,7 +43,7 @@ Options
extern std::string strprintf(const char *format, ...);
int i = -42;
unsigned int u = 0xffffffff;
- return strprintf("%d %u\n", i, u);
+ return strprintf("%u %d\n", i, u);
would be converted to
More information about the cfe-commits
mailing list