Bug 1473217 - Part 3: Enable clang-tidy's misc-unused-raii warnings. r?andi draft
authorChris Peterson <cpeterson@mozilla.com>
Mon, 02 Jul 2018 10:52:35 -0700
changeset 814344 0b0ca6dbde1a6c72c80b83a580b67768d2e36b14
parent 814214 3295686df39694fb234318c684a335621d164294
push id115169
push usercpeterson@mozilla.com
push dateThu, 05 Jul 2018 01:18:25 +0000
reviewersandi
bugs1473217
milestone63.0a1
Bug 1473217 - Part 3: Enable clang-tidy's misc-unused-raii warnings. r?andi And add a clang-tidy test for misc-unused-raii. MozReview-Commit-ID: KDYoF3YEbMu
tools/clang-tidy/config.yaml
tools/clang-tidy/test/misc-unused-raii.cpp
tools/clang-tidy/test/misc-unused-raii.json
--- a/tools/clang-tidy/config.yaml
+++ b/tools/clang-tidy/config.yaml
@@ -37,16 +37,18 @@ clang_checkers:
   - name: misc-forward-declaration-namespace
     # Name with clang tidy 6.0. We are currently using 5.0
     # - name: bugprone-forward-declaration-namespace
     publish: !!bool yes
   - name: misc-suspicious-missing-comma
     publish: !!bool yes
   - name: misc-suspicious-semicolon
     publish: !!bool yes
+  - name: misc-unused-raii
+    publish: !!bool yes
   - name: misc-unused-using-decls
     publish: !!bool yes
   - name: modernize-avoid-bind
     publish: !!bool yes
     restricted-platforms:
       - win32
       - win64
   - name: modernize-loop-convert
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/misc-unused-raii.cpp
@@ -0,0 +1,25 @@
+// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-unused-raii.html
+
+struct scoped_lock
+{
+  scoped_lock() {}
+  ~scoped_lock() {}
+};
+
+#define SCOPED_LOCK_MACRO(m) scoped_lock()
+
+struct trivial_scoped_lock
+{
+  trivial_scoped_lock() {}
+};
+
+scoped_lock test()
+{
+  scoped_lock(); // misc-unused-raii warning!
+
+  SCOPED_LOCK_MACRO(); // no warning for macros
+
+  trivial_scoped_lock(); // no warning for trivial objects without destructors
+
+  return scoped_lock(); // no warning for return values
+}
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/misc-unused-raii.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"object destroyed immediately after creation; did you mean to name the object?\", \"misc-unused-raii\"]]"
\ No newline at end of file