2015-12-30 18:24:40 +08:00
|
|
|
//===--- UnnecessaryCopyInitialization.h - clang-tidy------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-12-30 18:24:40 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
|
|
|
|
|
2019-03-25 20:38:26 +08:00
|
|
|
#include "../ClangTidyCheck.h"
|
2015-12-30 18:24:40 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace performance {
|
|
|
|
|
2016-03-06 05:17:58 +08:00
|
|
|
// The check detects local variable declarations that are copy initialized with
|
|
|
|
// the const reference of a function call or the const reference of a method
|
|
|
|
// call whose object is guaranteed to outlive the variable's scope and suggests
|
|
|
|
// to use a const reference.
|
2015-12-30 18:24:40 +08:00
|
|
|
//
|
|
|
|
// The check currently only understands a subset of variables that are
|
|
|
|
// guaranteed to outlive the const reference returned, namely: const variables,
|
|
|
|
// const references, and const pointers to const.
|
|
|
|
class UnnecessaryCopyInitialization : public ClangTidyCheck {
|
|
|
|
public:
|
2018-10-12 21:05:21 +08:00
|
|
|
UnnecessaryCopyInitialization(StringRef Name, ClangTidyContext *Context);
|
2020-06-28 22:18:08 +08:00
|
|
|
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override{
|
|
|
|
return LangOpts.CPlusPlus;
|
|
|
|
}
|
2015-12-30 18:24:40 +08:00
|
|
|
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
|
|
|
|
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
2018-10-12 21:05:21 +08:00
|
|
|
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
|
2016-03-23 17:33:07 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void handleCopyFromMethodReturn(const VarDecl &Var, const Stmt &BlockStmt,
|
2016-05-31 08:25:57 +08:00
|
|
|
bool IssueFix, const VarDecl *ObjectArg,
|
|
|
|
ASTContext &Context);
|
2016-03-23 17:33:07 +08:00
|
|
|
void handleCopyFromLocalVar(const VarDecl &NewVar, const VarDecl &OldVar,
|
2016-05-13 10:47:56 +08:00
|
|
|
const Stmt &BlockStmt, bool IssueFix,
|
|
|
|
ASTContext &Context);
|
2018-10-12 21:05:21 +08:00
|
|
|
const std::vector<std::string> AllowedTypes;
|
2015-12-30 18:24:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace performance
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_UNNECESSARY_COPY_INITIALIZATION_H
|