aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/CXXInheritance.cpp
diff options
context:
space:
mode:
authorMatheus Izvekov <mizvekov@gmail.com>2025-08-25 20:18:56 -0300
committerGitHub <noreply@github.com>2025-08-25 20:18:56 -0300
commitdc8596d5485a52abee2967cec72f81ef4872270c (patch)
tree5d0b5cbc1fed95f3b9aae2b39387c0f2b4d0e47c /clang/lib/AST/CXXInheritance.cpp
parent1ba8b36fef84bedb0a657b570076ec1a47e9061d (diff)
downloadllvm-dc8596d5485a52abee2967cec72f81ef4872270c.zip
llvm-dc8596d5485a52abee2967cec72f81ef4872270c.tar.gz
llvm-dc8596d5485a52abee2967cec72f81ef4872270c.tar.bz2
[clang] NFC: change more places to use Type::getAsTagDecl and friends (#155313)
This changes a bunch of places which use getAs<TagType>, including derived types, just to obtain the tag definition. This is preparation for #155028, offloading all the changes that PR used to introduce which don't depend on any new helpers.
Diffstat (limited to 'clang/lib/AST/CXXInheritance.cpp')
-rw-r--r--clang/lib/AST/CXXInheritance.cpp27
1 files changed, 7 insertions, 20 deletions
diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index e4b77ed..0ced210 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -128,17 +128,11 @@ bool CXXRecordDecl::forallBases(ForallBasesCallback BaseMatches) const {
const CXXRecordDecl *Record = this;
while (true) {
for (const auto &I : Record->bases()) {
- const RecordType *Ty = I.getType()->getAs<RecordType>();
- if (!Ty)
+ const auto *Base = I.getType()->getAsCXXRecordDecl();
+ if (!Base || !(Base->isBeingDefined() || Base->isCompleteDefinition()))
return false;
-
- CXXRecordDecl *Base = cast_if_present<CXXRecordDecl>(
- Ty->getOriginalDecl()->getDefinition());
- if (!Base ||
- (Base->isDependentContext() &&
- !Base->isCurrentInstantiation(Record))) {
+ if (Base->isDependentContext() && !Base->isCurrentInstantiation(Record))
return false;
- }
Queue.push_back(Base);
if (!BaseMatches(Base))
@@ -255,9 +249,7 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
const TemplateSpecializationType *TST =
BaseSpec.getType()->getAs<TemplateSpecializationType>();
if (!TST) {
- if (auto *RT = BaseSpec.getType()->getAs<RecordType>())
- BaseRecord = cast<CXXRecordDecl>(RT->getOriginalDecl())
- ->getDefinitionOrSelf();
+ BaseRecord = BaseSpec.getType()->getAsCXXRecordDecl();
} else {
TemplateName TN = TST->getTemplateName();
if (auto *TD =
@@ -347,11 +339,8 @@ bool CXXRecordDecl::lookupInBases(BaseMatchesCallback BaseMatches,
// base is a subobject of any other path; if so, then the
// declaration in this path are hidden by that patch.
for (const CXXBasePath &HidingP : Paths) {
- CXXRecordDecl *HidingClass = nullptr;
- if (const RecordType *Record =
- HidingP.back().Base->getType()->getAs<RecordType>())
- HidingClass = cast<CXXRecordDecl>(Record->getOriginalDecl())
- ->getDefinitionOrSelf();
+ auto *HidingClass =
+ HidingP.back().Base->getType()->getAsCXXRecordDecl();
if (!HidingClass)
break;
@@ -470,9 +459,7 @@ void FinalOverriderCollector::Collect(const CXXRecordDecl *RD,
= ++SubobjectCount[cast<CXXRecordDecl>(RD->getCanonicalDecl())];
for (const auto &Base : RD->bases()) {
- if (const RecordType *RT = Base.getType()->getAs<RecordType>()) {
- const CXXRecordDecl *BaseDecl =
- cast<CXXRecordDecl>(RT->getOriginalDecl())->getDefinitionOrSelf();
+ if (const auto *BaseDecl = Base.getType()->getAsCXXRecordDecl()) {
if (!BaseDecl->isPolymorphic())
continue;