Skip to content

Commit

Permalink
Do not copy the VisitorBase.
Browse files Browse the repository at this point in the history
This patch resolves a clang-tidy report that we are slicing the object when
trying to call cloneFunction.
  • Loading branch information
vgvassilev committed Aug 19, 2023
1 parent f3a7d33 commit 49d9aca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/clad/Differentiator/DerivativeBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace clad {
llvm::SmallVector<std::unique_ptr<ErrorEstimationHandler>, 4>
m_ErrorEstHandler;
DeclWithContext cloneFunction(const clang::FunctionDecl* FD,
clad::VisitorBase VB, clang::DeclContext* DC,
clad::VisitorBase& VB, clang::DeclContext* DC,
clang::Sema& m_Sema,
clang::ASTContext& m_Context,
clang::SourceLocation& noLoc,
Expand Down
16 changes: 6 additions & 10 deletions lib/Differentiator/DerivativeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,11 @@ namespace clad {
return false;
}

DeclWithContext
DerivativeBuilder::cloneFunction(const clang::FunctionDecl* FD,
clad::VisitorBase VD,
clang::DeclContext* DC,
clang::Sema& m_Sema,
clang::ASTContext& m_Context,
clang::SourceLocation& noLoc,
clang::DeclarationNameInfo name,
clang::QualType functionType) {
DeclWithContext DerivativeBuilder::cloneFunction(
const clang::FunctionDecl* FD, clad::VisitorBase& VB,
clang::DeclContext* DC, clang::Sema& m_Sema, clang::ASTContext& m_Context,
clang::SourceLocation& noLoc, clang::DeclarationNameInfo name,
clang::QualType functionType) {
FunctionDecl* returnedFD = nullptr;
NamespaceDecl* enclosingNS = nullptr;
if (isa<CXXMethodDecl>(FD)) {
Expand All @@ -116,7 +112,7 @@ namespace clad {
returnedFD->setAccess(FD->getAccess());
} else {
assert (isa<FunctionDecl>(FD) && "Unexpected!");
enclosingNS = VD.RebuildEnclosingNamespaces(DC);
enclosingNS = VB.RebuildEnclosingNamespaces(DC);
returnedFD = FunctionDecl::Create(m_Context,
m_Sema.CurContext,
noLoc,
Expand Down

0 comments on commit 49d9aca

Please sign in to comment.