[clang] [clang] Fix cast for injected types in case name lookup for dependent bases (PR #119024)
Vladislav Belov via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 8 02:16:11 PST 2024
https://github.com/vbe-sc updated https://github.com/llvm/llvm-project/pull/119024
>From ce758d5e8cf958edbfffeee8fe4c978011554b53 Mon Sep 17 00:00:00 2001
From: vb-sc <vladislav.belov at syntacore.com>
Date: Fri, 6 Dec 2024 23:06:01 +0300
Subject: [PATCH] [clang][NFC] Fix cast for injected types in case name lookup
for dependent bases
---
clang/lib/AST/CXXInheritance.cpp | 12 ++++++------
clang/test/CXX/drs/cwg5xx.cpp | 9 +++++++++
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index 10b8d524ff8978..ee5775837d5355 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -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())
+ ->getCanonicalDecl() == BaseRecord;
}
bool CXXRecordDecl::FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
@@ -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) {
@@ -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.
@@ -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.
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index 91a76fd2adbb6a..9a5a2f49db66b2 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -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;
};
@@ -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 at -1 {{field has incomplete type 'M' (aka 'void'}}
More information about the cfe-commits
mailing list