Skip to content

Commit

Permalink
[clang][AST][NFC] Make declarationReplaces()'s first parameter const
Browse files Browse the repository at this point in the history
And const qualify some local variables
  • Loading branch information
tbaederr committed Dec 19, 2023
1 parent 41096d1 commit 17fa04e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ class NamedDecl : public Decl {
///
/// \param IsKnownNewer \c true if this declaration is known to be newer
/// than \p OldD (for instance, if this declaration is newly-created).
bool declarationReplaces(NamedDecl *OldD, bool IsKnownNewer = true) const;
bool declarationReplaces(const NamedDecl *OldD,
bool IsKnownNewer = true) const;

/// Determine whether this declaration has linkage.
bool hasLinkage() const;
Expand Down
9 changes: 5 additions & 4 deletions clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,8 @@ static bool isRedeclarable(Decl::Kind K) {
llvm_unreachable("unknown decl kind");
}

bool NamedDecl::declarationReplaces(NamedDecl *OldD, bool IsKnownNewer) const {
bool NamedDecl::declarationReplaces(const NamedDecl *OldD,
bool IsKnownNewer) const {
assert(getDeclName() == OldD->getDeclName() && "Declaration name mismatch");

// Never replace one imported declaration with another; we need both results
Expand Down Expand Up @@ -1873,13 +1874,13 @@ bool NamedDecl::declarationReplaces(NamedDecl *OldD, bool IsKnownNewer) const {

// Using declarations can be replaced if they import the same name from the
// same context.
if (auto *UD = dyn_cast<UsingDecl>(this)) {
if (const auto *UD = dyn_cast<UsingDecl>(this)) {
ASTContext &Context = getASTContext();
return Context.getCanonicalNestedNameSpecifier(UD->getQualifier()) ==
Context.getCanonicalNestedNameSpecifier(
cast<UsingDecl>(OldD)->getQualifier());
}
if (auto *UUVD = dyn_cast<UnresolvedUsingValueDecl>(this)) {
if (const auto *UUVD = dyn_cast<UnresolvedUsingValueDecl>(this)) {
ASTContext &Context = getASTContext();
return Context.getCanonicalNestedNameSpecifier(UUVD->getQualifier()) ==
Context.getCanonicalNestedNameSpecifier(
Expand All @@ -1896,7 +1897,7 @@ bool NamedDecl::declarationReplaces(NamedDecl *OldD, bool IsKnownNewer) const {
// Check whether this is actually newer than OldD. We want to keep the
// newer declaration. This loop will usually only iterate once, because
// OldD is usually the previous declaration.
for (auto *D : redecls()) {
for (const auto *D : redecls()) {
if (D == OldD)
break;

Expand Down

0 comments on commit 17fa04e

Please sign in to comment.