CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
60 lines
2.0 KiB
ReStructuredText
60 lines
2.0 KiB
ReStructuredText
.. title:: clang-tidy - bugprone-unintended-char-ostream-output
|
|
|
|
bugprone-unintended-char-ostream-output
|
|
=======================================
|
|
|
|
Finds unintended character output from ``unsigned char`` and ``signed char`` to
|
|
an ``ostream``.
|
|
|
|
Normally, when ``unsigned char (uint8_t)`` or ``signed char (int8_t)`` is used,
|
|
it is more likely a number than a character. However, when it is passed
|
|
directly to ``std::ostream``'s ``operator<<``, the result is the character
|
|
output instead of the numeric value. This often contradicts the developer's
|
|
intent to print integer values.
|
|
|
|
.. code-block:: c++
|
|
|
|
uint8_t v = 65;
|
|
std::cout << v; // output 'A' instead of '65'
|
|
|
|
The check will suggest casting the value to an appropriate type to indicate the
|
|
intent, by default, it will cast to ``unsigned int`` for ``unsigned char`` and
|
|
``int`` for ``signed char``.
|
|
|
|
.. code-block:: c++
|
|
|
|
std::cout << static_cast<unsigned int>(v); // when v is unsigned char
|
|
std::cout << static_cast<int>(v); // when v is signed char
|
|
|
|
To avoid lengthy cast statements, add prefix ``+`` to the variable can
|
|
also suppress warnings because unary expression will promote the value
|
|
to an ``int``.
|
|
|
|
.. code-block:: c++
|
|
|
|
std::cout << +v;
|
|
|
|
Or cast to char to explicitly indicate that output should be a character.
|
|
|
|
.. code-block:: c++
|
|
|
|
std::cout << static_cast<char>(v);
|
|
|
|
Options
|
|
-------
|
|
|
|
.. option:: AllowedTypes
|
|
|
|
A semicolon-separated list of type names that will be treated like the ``char``
|
|
type: the check will not report variables declared with with these types or
|
|
explicit cast expressions to these types. Note that this distinguishes type
|
|
aliases from the original type, so specifying e.g. ``unsigned char`` here
|
|
will not suppress reports about ``uint8_t`` even if it is defined as a
|
|
``typedef`` alias for ``unsigned char``.
|
|
Default is `unsigned char;signed char`.
|
|
|
|
.. option:: CastTypeName
|
|
|
|
When `CastTypeName` is specified, the fix-it will use `CastTypeName` as the
|
|
cast target type. Otherwise, fix-it will automatically infer the type.
|