blob: 6850ab9a231edc2591d78be8c90f6f14766afaff [file] [log] [blame]
Benjamin Kramerda3658e2014-07-23 11:49:46 +00001//===--- UnusedRAII.h - clang-tidy ------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_RAII_H
11#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_RAII_H
12
13#include "../ClangTidy.h"
14
15namespace clang {
16namespace tidy {
17
18/// \brief Finds temporaries that look like RAII objects.
19///
20/// The canonical example for this is a scoped lock.
21/// \code
22/// {
23/// scoped_lock(&global_mutex);
24/// critical_section();
25/// }
26/// \endcode
27/// The destructor of the scoped_lock is called before the critical_section is
28/// entered, leaving it unprotected.
29///
30/// We apply a number of heuristics to reduce the false positive count of this
31/// check:
32/// - Ignore code expanded from macros. Testing frameworks make heavy use of
33/// this.
34/// - Ignore types with no user-declared constructor. Those are very unlikely
35/// to be RAII objects.
36/// - Ignore objects at the end of a compound statement (doesn't change behavior).
37/// - Ignore objects returned from a call.
38class UnusedRAIICheck : public ClangTidyCheck {
39public:
40 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
41 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
42};
43
44} // namespace tidy
45} // namespace clang
46
47#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_RAII_H