1 //===--- AvoidReferenceCoroutineParametersCheck.h - clang-tidy --*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDREFERENCECOROUTINEPARAMETERSCHECK_H 10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDREFERENCECOROUTINEPARAMETERSCHECK_H 11 12 #include "../ClangTidyCheck.h" 13 14 namespace clang { 15 namespace tidy { 16 namespace cppcoreguidelines { 17 18 /// Warns on coroutines that accept reference parameters. Accessing a reference 19 /// after a coroutine suspension point is not safe since the reference may no 20 /// longer be valid. This implements CppCoreGuideline CP.53. 21 /// 22 /// For the user-facing documentation see: 23 /// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.html 24 class AvoidReferenceCoroutineParametersCheck : public ClangTidyCheck { 25 public: 26 AvoidReferenceCoroutineParametersCheck(StringRef Name, 27 ClangTidyContext *Context) 28 : ClangTidyCheck(Name, Context) {} 29 void registerMatchers(ast_matchers::MatchFinder *Finder) override; 30 void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 31 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { 32 return LangOpts.CPlusPlus20; 33 } 34 }; 35 36 } // namespace cppcoreguidelines 37 } // namespace tidy 38 } // namespace clang 39 40 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDREFERENCECOROUTINEPARAMETERSCHECK_H 41