NoexceptMoveConstructorCheck.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //===--- NoexceptMoveConstructorCheck.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. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTMOVECONSTRUCTORCHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTMOVECONSTRUCTORCHECK_H
  10. #include "../ClangTidyCheck.h"
  11. namespace clang::tidy::performance {
  12. /// The check flags user-defined move constructors and assignment operators not
  13. /// marked with `noexcept` or marked with `noexcept(expr)` where `expr`
  14. /// evaluates to `false` (but is not a `false` literal itself).
  15. ///
  16. /// Move constructors of all the types used with STL containers, for example,
  17. /// need to be declared `noexcept`. Otherwise STL will choose copy constructors
  18. /// instead. The same is valid for move assignment operations.
  19. class NoexceptMoveConstructorCheck : public ClangTidyCheck {
  20. public:
  21. NoexceptMoveConstructorCheck(StringRef Name, ClangTidyContext *Context)
  22. : ClangTidyCheck(Name, Context) {}
  23. bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
  24. return LangOpts.CPlusPlus11;
  25. }
  26. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  27. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  28. };
  29. } // namespace clang::tidy::performance
  30. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTMOVECONSTRUCTORCHECK_H