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
--- 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