llvm/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp

//===--- UnnecessaryCopyInitialization.cpp - clang-tidy--------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "UnnecessaryCopyInitialization.h"
#include "../utils/DeclRefExprUtils.h"
#include "../utils/FixItHintUtils.h"
#include "../utils/LexerUtils.h"
#include "../utils/Matchers.h"
#include "../utils/OptionsUtils.h"
#include "clang/AST/Decl.h"
#include "clang/Basic/Diagnostic.h"
#include <optional>
#include <utility>

namespace clang::tidy::performance {
namespace {

usingnamespace::clang::ast_matchers;
StringRef;
allDeclRefExprs;
isOnlyUsedAsConst;

static constexpr StringRef ObjectArgId =;
static constexpr StringRef InitFunctionCallId =;
static constexpr StringRef MethodDeclId =;
static constexpr StringRef FunctionDeclId =;
static constexpr StringRef OldVarDeclId =;

void recordFixes(const VarDecl &Var, ASTContext &Context,
                 DiagnosticBuilder &Diagnostic) {}

std::optional<SourceLocation> firstLocAfterNewLine(SourceLocation Loc,
                                                   SourceManager &SM) {}

void recordRemoval(const DeclStmt &Stmt, ASTContext &Context,
                   DiagnosticBuilder &Diagnostic) {}

AST_MATCHER_FUNCTION_P(StatementMatcher,
                       isRefReturningMethodCallWithConstOverloads,
                       std::vector<StringRef>, ExcludedContainerTypes) {}

AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) {}

AST_MATCHER_FUNCTION_P(StatementMatcher, initializerReturnsReferenceToConst,
                       std::vector<StringRef>, ExcludedContainerTypes) {}

// This checks that the variable itself is only used as const, and also makes
// sure that it does not reference another variable that could be modified in
// the BlockStmt. It does this by checking the following:
// 1. If the variable is neither a reference nor a pointer then the
// isOnlyUsedAsConst() check is sufficient.
// 2. If the (reference or pointer) variable is not initialized in a DeclStmt in
// the BlockStmt. In this case its pointee is likely not modified (unless it
// is passed as an alias into the method as well).
// 3. If the reference is initialized from a reference to const. This is
// the same set of criteria we apply when identifying the unnecessary copied
// variable in this check to begin with. In this case we check whether the
// object arg or variable that is referenced is immutable as well.
static bool isInitializingVariableImmutable(
    const VarDecl &InitializingVar, const Stmt &BlockStmt, ASTContext &Context,
    const std::vector<StringRef> &ExcludedContainerTypes) {}

bool isVariableUnused(const VarDecl &Var, const Stmt &BlockStmt,
                      ASTContext &Context) {}

const SubstTemplateTypeParmType *getSubstitutedType(const QualType &Type,
                                                    ASTContext &Context) {}

bool differentReplacedTemplateParams(const QualType &VarType,
                                     const QualType &InitializerType,
                                     ASTContext &Context) {}

QualType constructorArgumentType(const VarDecl *OldVar,
                                 const BoundNodes &Nodes) {}

} // namespace

UnnecessaryCopyInitialization::UnnecessaryCopyInitialization(
    StringRef Name, ClangTidyContext *Context)
    :{}

void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {}

void UnnecessaryCopyInitialization::check(
    const MatchFinder::MatchResult &Result) {}

void UnnecessaryCopyInitialization::handleCopyFromMethodReturn(
    const CheckContext &Ctx, const VarDecl *ObjectArg) {}

void UnnecessaryCopyInitialization::handleCopyFromLocalVar(
    const CheckContext &Ctx, const VarDecl &OldVar) {}

void UnnecessaryCopyInitialization::diagnoseCopyFromMethodReturn(
    const CheckContext &Ctx) {}

void UnnecessaryCopyInitialization::diagnoseCopyFromLocalVar(
    const CheckContext &Ctx, const VarDecl &OldVar) {}

void UnnecessaryCopyInitialization::maybeIssueFixes(
    const CheckContext &Ctx, DiagnosticBuilder &Diagnostic) {}

void UnnecessaryCopyInitialization::storeOptions(
    ClangTidyOptions::OptionMap &Opts) {}

} // namespace clang::tidy::performance