Skip to content

[clang] Fix cast for injected types in case name lookup for dependent bases #119024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions clang/lib/AST/CXXInheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ bool CXXRecordDecl::FindBaseClass(const CXXBaseSpecifier *Specifier,
const CXXRecordDecl *BaseRecord) {
assert(BaseRecord->getCanonicalDecl() == BaseRecord &&
"User data for FindBaseClass is not canonical!");
return Specifier->getType()->castAs<RecordType>()->getDecl()
->getCanonicalDecl() == BaseRecord;
return cast<CXXRecordDecl>(Specifier->getType()->getAsRecordDecl())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this instead of:

Specifier->getType()->getAsCXXRecordDecl() ??

Same question throughout this patch.

->getCanonicalDecl() == BaseRecord;
}

bool CXXRecordDecl::FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
Expand All @@ -378,8 +378,8 @@ bool CXXRecordDecl::FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
assert(BaseRecord->getCanonicalDecl() == BaseRecord &&
"User data for FindBaseClass is not canonical!");
return Specifier->isVirtual() &&
Specifier->getType()->castAs<RecordType>()->getDecl()
->getCanonicalDecl() == BaseRecord;
cast<CXXRecordDecl>(Specifier->getType()->getAsRecordDecl())
->getCanonicalDecl() == BaseRecord;
}

static bool isOrdinaryMember(const NamedDecl *ND) {
Expand Down Expand Up @@ -692,7 +692,7 @@ AddIndirectPrimaryBases(const CXXRecordDecl *RD, ASTContext &Context,
"Cannot get indirect primary bases for class with dependent bases.");

const CXXRecordDecl *BaseDecl =
cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getDecl());
cast<CXXRecordDecl>(I.getType()->getAsRecordDecl());

// Only bases with virtual bases participate in computing the
// indirect primary virtual base classes.
Expand All @@ -714,7 +714,7 @@ CXXRecordDecl::getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const {
"Cannot get indirect primary bases for class with dependent bases.");

const CXXRecordDecl *BaseDecl =
cast<CXXRecordDecl>(I.getType()->castAs<RecordType>()->getDecl());
cast<CXXRecordDecl>(I.getType()->getAsRecordDecl());

// Only bases with virtual bases participate in computing the
// indirect primary virtual base classes.
Expand Down
9 changes: 9 additions & 0 deletions clang/test/CXX/drs/cwg5xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,11 @@ namespace cwg591 { // cwg591: 20
};
};

template <typename, bool> struct M {
class P;
int M;
};

template<typename T> struct A<T>::B::C : A<T> {
M m;
};
Expand All @@ -1224,6 +1229,10 @@ namespace cwg591 { // cwg591: 20
M m;
};

template<typename T, bool B> class M<T,B>::P : M {
int foo() { (void) M; }
};

template<typename T> struct A<T>::B::D : A<T*> {
M m;
// expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}
Expand Down
Loading