blob: 5d6ee4acee99f94751d80d14264c49e99466d696 [file] [log] [blame]
Alexander Kornienko5b982e52015-03-09 11:48:54 +00001//===--- UnusedRAIICheck.h - clang-tidy -------------------------*- C++ -*-===//
Benjamin Kramerda3658e2014-07-23 11:49:46 +00002//
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
Alexander Kornienko66580552015-03-09 16:52:33 +000010#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDRAIICHECK_H
11#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDRAIICHECK_H
Benjamin Kramerda3658e2014-07-23 11:49:46 +000012
13#include "../ClangTidy.h"
14
15namespace clang {
16namespace tidy {
Alexander Kornienko2b3124202015-03-02 12:25:03 +000017namespace misc {
Benjamin Kramerda3658e2014-07-23 11:49:46 +000018
19/// \brief Finds temporaries that look like RAII objects.
20///
21/// The canonical example for this is a scoped lock.
22/// \code
23/// {
24/// scoped_lock(&global_mutex);
25/// critical_section();
26/// }
27/// \endcode
28/// The destructor of the scoped_lock is called before the critical_section is
29/// entered, leaving it unprotected.
30///
31/// We apply a number of heuristics to reduce the false positive count of this
32/// check:
33/// - Ignore code expanded from macros. Testing frameworks make heavy use of
34/// this.
35/// - Ignore types with no user-declared constructor. Those are very unlikely
36/// to be RAII objects.
37/// - Ignore objects at the end of a compound statement (doesn't change behavior).
38/// - Ignore objects returned from a call.
39class UnusedRAIICheck : public ClangTidyCheck {
40public:
Alexander Kornienko6e0cbc82014-09-12 08:53:36 +000041 UnusedRAIICheck(StringRef Name, ClangTidyContext *Context)
42 : ClangTidyCheck(Name, Context) {}
Benjamin Kramerda3658e2014-07-23 11:49:46 +000043 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
44 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
45};
46
Alexander Kornienko2b3124202015-03-02 12:25:03 +000047} // namespace misc
Benjamin Kramerda3658e2014-07-23 11:49:46 +000048} // namespace tidy
49} // namespace clang
50
Alexander Kornienko66580552015-03-09 16:52:33 +000051#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDRAIICHECK_H