Skip to content

Commit 79fd12b

Browse files
committed
Add NOLINTNEXTLINE(bugprone-unused-return-value) in smart_holder_poc_test.cpp
Follow-on to #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`.
1 parent c46d136 commit 79fd12b

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

tests/pure_cpp/smart_holder_poc_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ TEST_CASE("from_raw_ptr_take_ownership+disown+reclaim_disowned", "[S]") {
164164
REQUIRE(*new_owner == 19);
165165
hld.reclaim_disowned(); // Manually veriified: without this, clang++ -fsanitize=address reports
166166
// "detected memory leaks".
167+
// NOLINTNEXTLINE(bugprone-unused-return-value)
167168
(void) new_owner.release(); // Manually verified: without this, clang++ -fsanitize=address
168169
// reports "attempting double-free".
169170
REQUIRE(hld.as_lvalue_ref<int>() == 19);

0 commit comments

Comments
 (0)