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
40 lines
1.7 KiB
ReStructuredText
40 lines
1.7 KiB
ReStructuredText
.. title:: clang-tidy - bugprone-unique-ptr-array-mismatch
|
|
|
|
bugprone-unique-ptr-array-mismatch
|
|
==================================
|
|
|
|
Finds initializations of C++ unique pointers to non-array type that are
|
|
initialized with an array.
|
|
|
|
If a pointer ``std::unique_ptr<T>`` is initialized with a new-expression
|
|
``new T[]`` the memory is not deallocated correctly. A plain ``delete`` is used
|
|
in this case to deallocate the target memory. Instead a ``delete[]`` call is
|
|
needed. A ``std::unique_ptr<T[]>`` uses the correct delete operator. The check
|
|
does not emit warning if an ``unique_ptr`` with user-specified deleter type is
|
|
used.
|
|
|
|
The check offers replacement of ``unique_ptr<T>`` to ``unique_ptr<T[]>`` if it
|
|
is used at a single variable declaration (one variable in one statement).
|
|
|
|
Example:
|
|
|
|
.. code-block:: c++
|
|
|
|
std::unique_ptr<Foo> x(new Foo[10]); // -> std::unique_ptr<Foo[]> x(new Foo[10]);
|
|
// ^ warning: unique pointer to non-array is initialized with array
|
|
std::unique_ptr<Foo> x1(new Foo), x2(new Foo[10]); // no replacement
|
|
// ^ warning: unique pointer to non-array is initialized with array
|
|
|
|
D d;
|
|
std::unique_ptr<Foo, D> x3(new Foo[10], d); // no warning (custom deleter used)
|
|
|
|
struct S {
|
|
std::unique_ptr<Foo> x(new Foo[10]); // no replacement in this case
|
|
// ^ warning: unique pointer to non-array is initialized with array
|
|
};
|
|
|
|
This check partially covers the CERT C++ Coding Standard rule
|
|
`MEM51-CPP. Properly deallocate dynamically allocated resources
|
|
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/MEM51-CPP.+Properly+deallocate+dynamically+allocated+resources>`_
|
|
However, only the ``std::unique_ptr`` case is detected by this check.
|