Skip to content

Commit 553d6cd

Browse files
committed
rework doc
1 parent 82cb4d0 commit 553d6cd

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

clang-tools-extra/docs/clang-tidy/checks/bugprone/unintended-char-ostream-output.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,23 @@ integer values.
1717
uint8_t v = 65;
1818
std::cout << v; // output 'A' instead of '65'
1919

20-
It could be fixed as
20+
The check will suggest casting the value to an appropriate type to indicate the
21+
intent, by default, it will cast to ``unsigned int`` for ``unsigned char`` and
22+
``int`` for ``signed char``.
2123

2224
.. code-block:: c++
2325

24-
std::cout << static_cast<uint32_t>(v);
26+
std::cout << static_cast<unsigned int>(v); // when v is unsigned char
27+
std::cout << static_cast<int>(v); // when v is signed char
2528

26-
Or cast to char to explicitly indicate the intent
29+
To avoid lengthy cast statements, add prefix ``+`` to the variable can also
30+
suppress warnings.
31+
32+
.. code-block:: c++
33+
34+
std::cout << +v;
35+
36+
Or cast to char to explicitly indicate that output should be a character.
2737

2838
.. code-block:: c++
2939

0 commit comments

Comments
 (0)