blob: 4d45c4acce8b7b7087be0f83c8fb32aa07c70816 [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:
Alexander Kornienko6e0cbc82014-09-12 08:53:36 +000040 UnusedRAIICheck(StringRef Name, ClangTidyContext *Context)
41 : ClangTidyCheck(Name, Context) {}
Benjamin Kramerda3658e2014-07-23 11:49:46 +000042 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
43 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
44};
45
46} // namespace tidy
47} // namespace clang
48
49#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_RAII_H