1 //===--- CoroutineHostileRAIICheck.h - clang-tidy ----------------*- C++-*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINESHOSTILERAIICHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINESHOSTILERAIICHECK_H
12 #include "../ClangTidyCheck.h"
13 #include "clang/AST/ASTTypeTraits.h"
14 #include "clang/ASTMatchers/ASTMatchFinder.h"
15 #include "llvm/ADT/StringRef.h"
18 namespace clang::tidy::misc
{
20 /// Detects when objects of certain hostile RAII types persists across
21 /// suspension points in a coroutine. Such hostile types include scoped-lockable
22 /// types and types belonging to a configurable denylist.
24 /// For the user-facing documentation see:
25 /// http://clang.llvm.org/extra/clang-tidy/checks/misc/coroutine-hostile-raii.html
26 class CoroutineHostileRAIICheck
: public ClangTidyCheck
{
28 CoroutineHostileRAIICheck(llvm::StringRef Name
, ClangTidyContext
*Context
);
30 bool isLanguageVersionSupported(const LangOptions
&LangOpts
) const override
{
31 return LangOpts
.CPlusPlus20
;
34 void registerMatchers(ast_matchers::MatchFinder
*Finder
) override
;
35 void storeOptions(ClangTidyOptions::OptionMap
&Opts
) override
;
36 void check(const ast_matchers::MatchFinder::MatchResult
&Result
) override
;
38 std::optional
<TraversalKind
> getCheckTraversalKind() const override
{
43 // List of fully qualified types which should not persist across a suspension
44 // point in a coroutine.
45 std::vector
<StringRef
> RAIITypesList
;
46 // List of fully qualified awaitable types which are considered safe to
48 std::vector
<StringRef
> AllowedAwaitablesList
;
51 } // namespace clang::tidy::misc
53 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINESHOSTILERAIICHECK_H