[PATCH] D124918: [clang-tidy] Add a new check for non-trivial unused variables.

Richard via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat May 14 12:27:04 PDT 2022


LegalizeAdulthood added inline comments.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/performance-unused-no-side-effect.rst:25-26
+
+A function is considered to "not read an argument unless the return value is
+used" in the following cases:
+
----------------
The quotes here don't feel like they're needed.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/performance-unused-no-side-effect.rst:35
+
+- A function listed in FunctionAllowList, if the argument is in index ``i`` and
+  bit ``i`` is set in the corresponding allow list entry.
----------------
Single backquotes around `FunctionAllowList`


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/performance-unused-no-side-effect.rst:93
+   {
+      "std::string": ["swap"],
+      "absl::int128": [],
----------------
Since `std::string` is just a type alias, shouldn't we be considering `basic_string`?
What about `wstring`?


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/performance-unused-no-side-effect.rst:103
+      "absl::string_view": ["swap", "copy"],
+      "std::string_view": ["swap", "copy"]
+   }
----------------
`string_view` is also just a type alias, there is `wstring_view`, etc.


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/performance-unused-no-side-effect.rst:115-152
+  {
+    "std::vector": ["swap"],
+    "std::pair": [],
+    "std::tuple": [],
+    "std::optional": ["swap"],
+    "std::variant": ["swap"],
+    "std::list": ["swap"],
----------------
It would be easier to scan this list if it were sorted alphabetically.  I see `basic_string` listed here, but not `basic_string_view`.  Is that intentional?


================
Comment at: clang-tools-extra/docs/clang-tidy/checks/performance-unused-no-side-effect.rst:172-173
+List of functions that are considered not to read some of their arguments
+unless their return value is read. Arguments are identified by a bitmask, where
+the i-th LSB being set indicates that the i-th argument is unused.
+
----------------
This isn't user-friendly at all.  Why not an array of argument indices starting at zero?


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/performance-unused-no-side-effect.cpp:118
+  (VecLoops).push_back(3);
+}
----------------
Should there be some test cases for user-defined template types with no side effects?

Also some test cases for the smart pointer cases?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124918/new/

https://reviews.llvm.org/D124918



More information about the cfe-commits mailing list