Detects function calls where the return value is unused.
Checked functions can be configured.
Differential D41655
[clang-tidy] New check bugprone-unused-return-value khuttun on Jan 1 2018, 4:43 AM. Authored by
Details Detects function calls where the return value is unused. Checked functions can be configured.
Diff Detail
Event Timeline
Comment Actions What do you exactly mean by list? It seems some other checks use comma or semicolon separators in their configuration strings, but is that really more user friendly than using "|"? At least now it's clear that the whole string is a regex.
Comment Actions High Integrity C++ has the rule 17.5.1 Do not ignore the result of std::remove, std::remove_if or std::unique. Do we want to add those to the preconfigured list?
Comment Actions To me these sound like reasonable additions. I can add them and run the checker against LLVM source to see if we get any false positives with them. I also noticed that the checker currently misses unused values inside other kinds of statements than compound statement (if statements, case statements etc.). I will also update the checker to handle these.
Comment Actions
Comment Actions The checker reports 7 warnings on LLVM + Clang code bases, all on std::unique_ptr::release: lib/Bitcode/Reader/BitReader.cpp:114:3
lib/ExecutionEngine/ExecutionEngine.cpp:149:7
lib/Target/AMDGPU/GCNIterativeScheduler.cpp:196:5
lib/AsmParser/LLParser.cpp:855:3
tools/clang/lib/Lex/ModuleMap.cpp:791:3
tools/clang/tools/extra/clangd/Compiler.cpp:61:3
unittests/Support/Casting.cpp:144:3
Comment Actions Agreed.
False positive.
False positive, but a bad code smell given that the assignment operator will perform the release.
False positive.
False positive.
False positive. From what I can tell of these reports, they almost all boil down to ignoring the call to release() because the pointer is no longer owned by the unique_ptr. This is a pretty reasonable code pattern, but it also seems reasonable to expect users to cast the result to void to silence the warning, so I think this is fine. Have you checked any other large C++ code bases, like Qt or boost? Comment Actions
Yep, there's already code also in LLVM where the release() return value is cast to void, for example in lib/Bitcode/Reader/BitReader.cpp. I haven't run the checker on other large code bases yet, but I can test also that.
Comment Actions I changed the checker to use hasAnyName. Checking for unique_ptr::release() and all the empty() functions is removed. The checker doesn't report any warnings from LLVM + clang codebases now. Comment Actions LG. Thank you! BTW, there's an old related patch https://reviews.llvm.org/D17043, which mostly focuses on member functions of STL containers. It might be useful as a reference (there's a pretty extensive list of member functions and containers). Comment Actions Yes please, I don't have commit access to the repo. I think the next step for improving this checker could be to make it work with class template member functions. That would allow to add checking also to those container functions that D17043 handles. Comment Actions The patch doesn't apply cleanly. Please rebase against current HEAD.
Yep, sounds reasonable. Thank you for working on this! |