From 79fd12b8ccb8cc9c0ab45162529cf2510730e4ec Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 29 Jul 2024 19:30:51 -0700 Subject: [PATCH] Add `NOLINTNEXTLINE(bugprone-unused-return-value)` in smart_holder_poc_test.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-on to https://github.com/pybind/pybind11/pull/5272 — clang-tidy upgrade (to version 18) Fixes this error: ``` /__w/pybind11/pybind11/tests/pure_cpp/smart_holder_poc_test.cpp:167:12: error: the value returned by this function should not be disregarded; neglecting it may lead to errors [bugprone-unused-return-value,-warnings-as-errors] 167 | (void) new_owner.release(); // Manually verified: without this, clang++ -fsanitize=address | ^~~~~~~~~~~~~~~~~~~ ``` See also: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/unused-return-value.html Specifically there: > std::unique_ptr::release(). Not using the return value can lead to resource leaks if the same pointer isn’t stored anywhere else. Often, ignoring the release() return value indicates that the programmer confused the function with reset(). I.e. the only way to tell clang-tidy that the smart_holder_poc_test.cpp is correct is to add the `NOLINT`. --- tests/pure_cpp/smart_holder_poc_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/pure_cpp/smart_holder_poc_test.cpp b/tests/pure_cpp/smart_holder_poc_test.cpp index f820b9bf68..a9ad0364ef 100644 --- a/tests/pure_cpp/smart_holder_poc_test.cpp +++ b/tests/pure_cpp/smart_holder_poc_test.cpp @@ -164,6 +164,7 @@ TEST_CASE("from_raw_ptr_take_ownership+disown+reclaim_disowned", "[S]") { REQUIRE(*new_owner == 19); hld.reclaim_disowned(); // Manually veriified: without this, clang++ -fsanitize=address reports // "detected memory leaks". + // NOLINTNEXTLINE(bugprone-unused-return-value) (void) new_owner.release(); // Manually verified: without this, clang++ -fsanitize=address // reports "attempting double-free". REQUIRE(hld.as_lvalue_ref() == 19);