Skip to content

Commit

Permalink
[clang] Fix all instances of -Wqual-class-return-type by removing sup…
Browse files Browse the repository at this point in the history
…erfluous `const`

No intended functional change.
  • Loading branch information
Quuxplusone committed Oct 9, 2024
1 parent 37913b7 commit b5a4e52
Show file tree
Hide file tree
Showing 69 changed files with 239 additions and 255 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/AST/APValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ class APValue {
return const_cast<APValue*>(this)->getComplexFloatImag();
}

const LValueBase getLValueBase() const;
LValueBase getLValueBase() const;
CharUnits &getLValueOffset();
const CharUnits &getLValueOffset() const {
return const_cast<APValue*>(this)->getLValueOffset();
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
const TargetInfo &getTargetInfo() const { return *Target; }
const TargetInfo *getAuxTargetInfo() const { return AuxTarget; }

const QualType GetHigherPrecisionFPType(QualType ElementType) const {
QualType GetHigherPrecisionFPType(QualType ElementType) const {
const auto *CurrentBT = cast<BuiltinType>(ElementType);
switch (CurrentBT->getKind()) {
case BuiltinType::Kind::Half:
Expand Down
15 changes: 4 additions & 11 deletions clang/include/clang/AST/DeclCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ class ExplicitSpecifier {
void setExpr(Expr *E) { ExplicitSpec.setPointer(E); }
// Retrieve the explicit specifier in the given declaration, if any.
static ExplicitSpecifier getFromDecl(FunctionDecl *Function);
static const ExplicitSpecifier getFromDecl(const FunctionDecl *Function) {
static ExplicitSpecifier getFromDecl(const FunctionDecl *Function) {
return getFromDecl(const_cast<FunctionDecl *>(Function));
}
static ExplicitSpecifier Invalid() {
Expand Down Expand Up @@ -1996,7 +1996,7 @@ class CXXDeductionGuideDecl : public FunctionDecl {
GlobalDeclID ID);

ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; }
const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; }
ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; }

/// Return true if the declaration is already resolved to be explicit.
bool isExplicit() const { return ExplicitSpec.isExplicit(); }
Expand Down Expand Up @@ -2614,10 +2614,7 @@ class CXXConstructorDecl final
CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit();
}

ExplicitSpecifier getExplicitSpecifier() {
return getCanonicalDecl()->getExplicitSpecifierInternal();
}
const ExplicitSpecifier getExplicitSpecifier() const {
ExplicitSpecifier getExplicitSpecifier() const {
return getCanonicalDecl()->getExplicitSpecifierInternal();
}

Expand Down Expand Up @@ -2897,11 +2894,7 @@ class CXXConversionDecl : public CXXMethodDecl {
Expr *TrailingRequiresClause = nullptr);
static CXXConversionDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);

ExplicitSpecifier getExplicitSpecifier() {
return getCanonicalDecl()->ExplicitSpec;
}

const ExplicitSpecifier getExplicitSpecifier() const {
ExplicitSpecifier getExplicitSpecifier() const {
return getCanonicalDecl()->ExplicitSpec;
}

Expand Down
12 changes: 2 additions & 10 deletions clang/include/clang/AST/ExprCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -4991,19 +4991,11 @@ class CXXParenListInitExpr final

void updateDependence() { setDependence(computeDependence(this)); }

ArrayRef<Expr *> getInitExprs() {
ArrayRef<Expr *> getInitExprs() const {
return ArrayRef(getTrailingObjects<Expr *>(), NumExprs);
}

const ArrayRef<Expr *> getInitExprs() const {
return ArrayRef(getTrailingObjects<Expr *>(), NumExprs);
}

ArrayRef<Expr *> getUserSpecifiedInitExprs() {
return ArrayRef(getTrailingObjects<Expr *>(), NumUserSpecifiedExprs);
}

const ArrayRef<Expr *> getUserSpecifiedInitExprs() const {
ArrayRef<Expr *> getUserSpecifiedInitExprs() const {
return ArrayRef(getTrailingObjects<Expr *>(), NumUserSpecifiedExprs);
}

Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/ExprOpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class OMPIteratorExpr final

/// Gets the iterator range for the given iterator.
IteratorRange getIteratorRange(unsigned I);
const IteratorRange getIteratorRange(unsigned I) const {
IteratorRange getIteratorRange(unsigned I) const {
return const_cast<OMPIteratorExpr *>(this)->getIteratorRange(I);
}

Expand Down
3 changes: 1 addition & 2 deletions clang/include/clang/AST/Stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1533,8 +1533,7 @@ class DeclStmt : public Stmt {
const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
Decl *getSingleDecl() { return DG.getSingleDecl(); }

const DeclGroupRef getDeclGroup() const { return DG; }
DeclGroupRef getDeclGroup() { return DG; }
DeclGroupRef getDeclGroup() const { return DG; }
void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }

void setStartLoc(SourceLocation L) { StartLoc = L; }
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/TypeLoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,7 @@ class AutoTypeLoc

// FIXME: Several of the following functions can be removed. Instead the
// caller can directly work with the ConceptReference.
const NestedNameSpecifierLoc getNestedNameSpecifierLoc() const {
NestedNameSpecifierLoc getNestedNameSpecifierLoc() const {
if (const auto *CR = getConceptReference())
return CR->getNestedNameSpecifierLoc();
return NestedNameSpecifierLoc();
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1828,7 +1828,7 @@ class TargetInfo : public TransferrableTargetInfo,

/// Returns the version of the darwin target variant SDK which was used during
/// the compilation if one was specified, or an empty version otherwise.
const std::optional<VersionTuple> getDarwinTargetVariantSDKVersion() const {
std::optional<VersionTuple> getDarwinTargetVariantSDKVersion() const {
return !getTargetOpts().DarwinTargetVariantSDKVersion.empty()
? getTargetOpts().DarwinTargetVariantSDKVersion
: std::optional<VersionTuple>();
Expand Down
8 changes: 4 additions & 4 deletions clang/include/clang/Lex/MacroInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class MacroDirective {

inline DefInfo getPreviousDefinition();

const DefInfo getPreviousDefinition() const {
DefInfo getPreviousDefinition() const {
return const_cast<DefInfo *>(this)->getPreviousDefinition();
}
};
Expand All @@ -403,7 +403,7 @@ class MacroDirective {
/// macro definition directive along with info about its undefined location
/// (if there is one) and if it is public or private.
DefInfo getDefinition();
const DefInfo getDefinition() const {
DefInfo getDefinition() const {
return const_cast<MacroDirective *>(this)->getDefinition();
}

Expand All @@ -420,8 +420,8 @@ class MacroDirective {

/// Find macro definition active in the specified source location. If
/// this macro was not defined there, return NULL.
const DefInfo findDirectiveAtLoc(SourceLocation L,
const SourceManager &SM) const;
DefInfo findDirectiveAtLoc(SourceLocation L,
const SourceManager &SM) const;

void dump() const;

Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/CodeCompleteConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ class CodeCompleteConsumer {
/// Retrieve the function ProtoTypeLoc candidate.
/// This can be called for any Kind, but returns null for kinds
/// other than CK_FunctionProtoTypeLoc.
const FunctionProtoTypeLoc getFunctionProtoTypeLoc() const;
FunctionProtoTypeLoc getFunctionProtoTypeLoc() const;

const TemplateDecl *getTemplate() const {
assert(getKind() == CK_Template && "Not a template");
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/SemaOpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class SemaOpenMP : public SemaBase {
bool ActOnStartOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI);

/// Called at the end of target region i.e. '#pragma omp end declare target'.
const DeclareTargetContextInfo ActOnOpenMPEndDeclareTargetDirective();
DeclareTargetContextInfo ActOnOpenMPEndDeclareTargetDirective();

/// Called once a target context is completed, that can be when a
/// '#pragma omp end declare target' was encountered or when a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ class NoStoreFuncVisitor final : public NoStateChangeFuncVisitor {
/// Note that \p Vec is passed by value, leading to quadratic copying cost,
/// but it's OK in practice since its length is limited to DEREFERENCE_LIMIT.
/// \return A chain fields leading to the region of interest or std::nullopt.
const std::optional<RegionVector>
std::optional<RegionVector>
findRegionOfInterestInRecord(const RecordDecl *RD, ProgramStateRef State,
const MemRegion *R, const RegionVector &Vec = {},
int depth = 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class CallEvent {
std::optional<SVal> getReturnValueUnderConstruction() const;

// Returns the CallEvent representing the caller of this function
const CallEventRef<> getCaller() const;
CallEventRef<> getCaller() const;

// Returns true if the function was called from a standard library function.
// If not or could not get the caller (it may be a top level function)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CheckerContext {
/// the state of the program before the checker ran. Note, checkers should
/// not retain the node in their state since the nodes might get invalidated.
ExplodedNode *getPredecessor() { return Pred; }
const ProgramPoint getLocation() const { return Location; }
ProgramPoint getLocation() const { return Location; }
const ProgramStateRef &getState() const { return Pred->getState(); }

/// Check if the checker changed the state of the execution; ex: added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ class PointerToMember : public NonLoc {
using PTMDataType =
llvm::PointerUnion<const NamedDecl *, const PointerToMemberData *>;

const PTMDataType getPTMData() const {
PTMDataType getPTMData() const {
return PTMDataType::getFromOpaqueValue(const_cast<void *>(Data));
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/APValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ bool APValue::toIntegralConstant(APSInt &Result, QualType SrcTy,
return false;
}

const APValue::LValueBase APValue::getLValueBase() const {
APValue::LValueBase APValue::getLValueBase() const {
assert(isLValue() && "Invalid accessor");
return ((const LV *)(const void *)&Data)->Base;
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Function final {

/// Returns the name of the function decl this code
/// was generated for.
const std::string getName() const {
std::string getName() const {
if (!Source || !getDecl())
return "<<expr>>";

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Record::Record(const RecordDecl *Decl, BaseList &&SrcBases,
VirtualBaseMap[V.Decl] = &V;
}

const std::string Record::getName() const {
std::string Record::getName() const {
std::string Ret;
llvm::raw_string_ostream OS(Ret);
Decl->getNameForDiagnostic(OS, Decl->getASTContext().getPrintingPolicy(),
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/Record.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Record final {
/// Returns the underlying declaration.
const RecordDecl *getDecl() const { return Decl; }
/// Returns the name of the underlying declaration.
const std::string getName() const;
std::string getName() const;
/// Checks if the record is a union.
bool isUnion() const { return IsUnion; }
/// Checks if the record is an anonymous union.
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@ namespace {
bool IsNullPtr : 1;
bool InvalidBase : 1;

const APValue::LValueBase getLValueBase() const { return Base; }
APValue::LValueBase getLValueBase() const { return Base; }
CharUnits &getLValueOffset() { return Offset; }
const CharUnits &getLValueOffset() const { return Offset; }
SubobjectDesignator &getLValueDesignator() { return Designator; }
Expand Down Expand Up @@ -12346,7 +12346,7 @@ static bool isDesignatorAtObjectEnd(const ASTContext &Ctx, const LValue &LVal) {
return FD->getFieldIndex() + 1 == Layout.getFieldCount();
};

auto &Base = LVal.getLValueBase();
const auto &Base = LVal.getLValueBase();
if (auto *ME = dyn_cast_or_null<MemberExpr>(Base.dyn_cast<const Expr *>())) {
if (auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
bool Invalid;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ItaniumMangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ bool CXXNameMangler::isStdNamespace(const DeclContext *DC) {
return isStd(cast<NamespaceDecl>(DC));
}

static const GlobalDecl
static GlobalDecl
isTemplate(GlobalDecl GD, const TemplateArgumentList *&TemplateArgs) {
const NamedDecl *ND = cast<NamedDecl>(GD.getDecl());
// Check if we have a function template.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/BackendConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class BackendConsumer : public ASTConsumer {

/// Get the best possible source location to represent a diagnostic that
/// may have associated debug info.
const FullSourceLoc getBestLocationFromDebugLoc(
FullSourceLoc getBestLocationFromDebugLoc(
const llvm::DiagnosticInfoWithLocationBase &D,
bool &BadDebugInfo, StringRef &Filename,
unsigned &Line, unsigned &Column) const;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CGCalleeInfo {
const FunctionProtoType *getCalleeFunctionProtoType() const {
return CalleeProtoTy;
}
const GlobalDecl getCalleeDecl() const { return CalleeDecl; }
GlobalDecl getCalleeDecl() const { return CalleeDecl; }
};

/// All available information about a concrete callee.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ bool BackendConsumer::ResourceLimitDiagHandler(
return true;
}

const FullSourceLoc BackendConsumer::getBestLocationFromDebugLoc(
FullSourceLoc BackendConsumer::getBestLocationFromDebugLoc(
const llvm::DiagnosticInfoWithLocationBase &D, bool &BadDebugInfo,
StringRef &Filename, unsigned &Line, unsigned &Column) const {
SourceManager &SourceMgr = Context->getSourceManager();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@ StringRef CodeGenModule::getBlockMangledName(GlobalDecl GD,
return Result.first->first();
}

const GlobalDecl CodeGenModule::getMangledNameDecl(StringRef Name) {
GlobalDecl CodeGenModule::getMangledNameDecl(StringRef Name) {
auto it = MangledDeclNames.begin();
while (it != MangledDeclNames.end()) {
if (it->second == Name)
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ class CodeGenModule : public CodeGenTypeCache {

StringRef getMangledName(GlobalDecl GD);
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD);
const GlobalDecl getMangledNameDecl(StringRef);
GlobalDecl getMangledNameDecl(StringRef);

void EmitTentativeDefinition(const VarDecl *D);

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Lex/MacroInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ MacroDirective::DefInfo MacroDirective::getDefinition() {
return DefInfo(nullptr, UndefLoc, !isPublic || *isPublic);
}

const MacroDirective::DefInfo
MacroDirective::DefInfo
MacroDirective::findDirectiveAtLoc(SourceLocation L,
const SourceManager &SM) const {
assert(L.isValid() && "SourceLocation is invalid.");
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/CodeCompleteConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ CodeCompleteConsumer::OverloadCandidate::getFunctionType() const {
llvm_unreachable("Invalid CandidateKind!");
}

const FunctionProtoTypeLoc
FunctionProtoTypeLoc
CodeCompleteConsumer::OverloadCandidate::getFunctionProtoTypeLoc() const {
if (Kind == CK_FunctionProtoTypeLoc)
return ProtoTypeLoc;
Expand Down
Loading

0 comments on commit b5a4e52

Please sign in to comment.