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
64 lines
1.9 KiB
ReStructuredText
64 lines
1.9 KiB
ReStructuredText
.. title:: clang-tidy - bugprone-stringview-nullptr
|
|
|
|
bugprone-stringview-nullptr
|
|
===========================
|
|
Checks for various ways that the ``const CharT*`` constructor of
|
|
``std::basic_string_view`` can be passed a null argument and replaces them
|
|
with the default constructor in most cases. For the comparison operators,
|
|
braced initializer list does not compile so instead a call to ``.empty()``
|
|
or the empty string literal are used, where appropriate.
|
|
|
|
This prevents code from invoking behavior which is unconditionally undefined.
|
|
The single-argument ``const CharT*`` constructor does not check for the null
|
|
case before dereferencing its input. The standard is slated to add an
|
|
explicitly-deleted overload to catch some of these cases: wg21.link/p2166
|
|
|
|
To catch the additional cases of ``NULL`` (which expands to ``__null``) and
|
|
``0``, first run the ``modernize-use-nullptr`` check to convert the callers to
|
|
``nullptr``.
|
|
|
|
.. code-block:: c++
|
|
|
|
std::string_view sv = nullptr;
|
|
|
|
sv = nullptr;
|
|
|
|
bool is_empty = sv == nullptr;
|
|
bool isnt_empty = sv != nullptr;
|
|
|
|
accepts_sv(nullptr);
|
|
|
|
accepts_sv({{}}); // A
|
|
|
|
accepts_sv({nullptr, 0}); // B
|
|
|
|
is translated into...
|
|
|
|
.. code-block:: c++
|
|
|
|
std::string_view sv = {};
|
|
|
|
sv = {};
|
|
|
|
bool is_empty = sv.empty();
|
|
bool isnt_empty = !sv.empty();
|
|
|
|
accepts_sv("");
|
|
|
|
accepts_sv(""); // A
|
|
|
|
accepts_sv({nullptr, 0}); // B
|
|
|
|
.. note::
|
|
|
|
The source pattern with trailing comment "A" selects the ``(const CharT*)``
|
|
constructor overload and then value-initializes the pointer, causing a null
|
|
dereference. It happens to not include the ``nullptr`` literal, but it is
|
|
still within the scope of this ClangTidy check.
|
|
|
|
.. note::
|
|
|
|
The source pattern with trailing comment "B" selects the
|
|
``(const CharT*, size_type)`` constructor which is perfectly valid, since the
|
|
length argument is ``0``. It is not changed by this ClangTidy check.
|