ForwardingReferenceOverloadCheck.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //===--- ForwardingReferenceOverloadCheck.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_BUGPRONE_FORWARDINGREFERENCEOVERLOADCHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDINGREFERENCEOVERLOADCHECK_H
  10. #include "../ClangTidyCheck.h"
  11. namespace clang::tidy::bugprone {
  12. /// The checker looks for constructors that can act as copy or move constructors
  13. /// through their forwarding reference parameters. If a non const lvalue
  14. /// reference is passed to the constructor, the forwarding reference parameter
  15. /// can be a perfect match while the const reference parameter of the copy
  16. /// constructor can't. The forwarding reference constructor will be called,
  17. /// which can lead to confusion.
  18. /// For detailed description of this problem see: Scott Meyers, Effective Modern
  19. /// C++ Design, item 26.
  20. ///
  21. /// For the user-facing documentation see:
  22. /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/forwarding-reference-overload.html
  23. class ForwardingReferenceOverloadCheck : public ClangTidyCheck {
  24. public:
  25. ForwardingReferenceOverloadCheck(StringRef Name, ClangTidyContext *Context)
  26. : ClangTidyCheck(Name, Context) {}
  27. bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
  28. return LangOpts.CPlusPlus11;
  29. }
  30. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  31. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  32. };
  33. } // namespace clang::tidy::bugprone
  34. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDINGREFERENCEOVERLOADCHECK_H