Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:18

0001 //===--- MoveForwardingReferenceCheck.h - clang-tidy ----------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVEFORWARDINGREFERENCECHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVEFORWARDINGREFERENCECHECK_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 
0014 namespace clang::tidy::bugprone {
0015 
0016 /// The check warns if std::move is applied to a forwarding reference (i.e. an
0017 /// rvalue reference of a function template argument type).
0018 ///
0019 /// If a developer is unaware of the special rules for template argument
0020 /// deduction on forwarding references, it will seem reasonable to apply
0021 /// std::move to the forwarding reference, in the same way that this would be
0022 /// done for a "normal" rvalue reference.
0023 ///
0024 /// This has a consequence that is usually unwanted and possibly surprising: if
0025 /// the function that takes the forwarding reference as its parameter is called
0026 /// with an lvalue, that lvalue will be moved from (and hence placed into an
0027 /// indeterminate state) even though no std::move was applied to the lvalue at
0028 /// the call site.
0029 //
0030 /// The check suggests replacing the std::move with a std::forward.
0031 ///
0032 /// For the user-facing documentation see:
0033 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/move-forwarding-reference.html
0034 class MoveForwardingReferenceCheck : public ClangTidyCheck {
0035 public:
0036   MoveForwardingReferenceCheck(StringRef Name, ClangTidyContext *Context)
0037       : ClangTidyCheck(Name, Context) {}
0038   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
0039     return LangOpts.CPlusPlus11;
0040   }
0041   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0042   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0043 };
0044 
0045 } // namespace clang::tidy::bugprone
0046 
0047 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVEFORWARDINGREFERENCECHECK_H