clang-tools
8.0.0
llvm.src
tools
clang
tools
extra
clang-tidy
bugprone
MoveForwardingReferenceCheck.h
Go to the documentation of this file.
1
//===--- MoveForwardingReferenceCheck.h - clang-tidy ----------------------===//
2
//
3
// The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVEFORWARDINGREFERENCECHECK_H
11
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVEFORWARDINGREFERENCECHECK_H
12
13
#include "../ClangTidy.h"
14
15
namespace
clang
{
16
namespace
tidy {
17
namespace
bugprone {
18
19
/// The check warns if std::move is applied to a forwarding reference (i.e. an
20
/// rvalue reference of a function template argument type).
21
///
22
/// If a developer is unaware of the special rules for template argument
23
/// deduction on forwarding references, it will seem reasonable to apply
24
/// std::move to the forwarding reference, in the same way that this would be
25
/// done for a "normal" rvalue reference.
26
///
27
/// This has a consequence that is usually unwanted and possibly surprising: if
28
/// the function that takes the forwarding reference as its parameter is called
29
/// with an lvalue, that lvalue will be moved from (and hence placed into an
30
/// indeterminate state) even though no std::move was applied to the lvalue at
31
/// the call site.
32
//
33
/// The check suggests replacing the std::move with a std::forward.
34
///
35
/// For the user-facing documentation see:
36
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-move-forwarding-reference.html
37
class
MoveForwardingReferenceCheck
:
public
ClangTidyCheck
{
38
public
:
39
MoveForwardingReferenceCheck
(StringRef
Name
,
ClangTidyContext
*Context)
40
:
ClangTidyCheck
(Name, Context) {}
41
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
42
void
check
(
const
ast_matchers::MatchFinder::MatchResult &
Result
)
override
;
43
};
44
45
}
// namespace bugprone
46
}
// namespace tidy
47
}
// namespace clang
48
49
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVEFORWARDINGREFERENCECHECK_H
clang::tidy::bugprone::MoveForwardingReferenceCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
MoveForwardingReferenceCheck.cpp:96
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidy.h:127
clang::tidy::bugprone::MoveForwardingReferenceCheck::MoveForwardingReferenceCheck
MoveForwardingReferenceCheck(StringRef Name, ClangTidyContext *Context)
Definition:
MoveForwardingReferenceCheck.h:39
clang::tidy::bugprone::MoveForwardingReferenceCheck
The check warns if std::move is applied to a forwarding reference (i.e.
Definition:
MoveForwardingReferenceCheck.h:37
clang::tidy::bugprone::MoveForwardingReferenceCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
MoveForwardingReferenceCheck.cpp:70
Name
static constexpr llvm::StringLiteral Name
Definition:
UppercaseLiteralSuffixCheck.cpp:28
Result
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
Definition:
ClangdServer.cpp:60
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition:
ChangeNamespace.cpp:18
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:100
Generated on Fri Mar 8 2019 13:35:28 for clang-tools by
1.8.13