• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===--- SlicingCheck.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_SLICING_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SLICING_H
11 
12 #include "../ClangTidyCheck.h"
13 
14 namespace clang {
15 namespace tidy {
16 namespace cppcoreguidelines {
17 
18 /// Flags slicing (incomplete copying of an object's state) of member variables
19 /// or vtable. See:
20 ///   - https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es63-dont-slice
21 ///     for the former, and
22 ///   - https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c145-access-polymorphic-objects-through-pointers-and-references
23 ///     for the latter
24 ///
25 /// For the user-facing documentation see:
26 /// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-slicing.html
27 class SlicingCheck : public ClangTidyCheck {
28 public:
SlicingCheck(StringRef Name,ClangTidyContext * Context)29   SlicingCheck(StringRef Name, ClangTidyContext *Context)
30       : ClangTidyCheck(Name, Context) {}
31   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
32   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
33 
34 private:
35   void DiagnoseSlicedOverriddenMethods(const Expr &call,
36                                        const CXXRecordDecl &DerivedDecl,
37                                        const CXXRecordDecl &BaseDecl);
38 };
39 
40 } // namespace cppcoreguidelines
41 } // namespace tidy
42 } // namespace clang
43 
44 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_SLICING_H
45