https://github.com/vbe-sc updated https://github.com/llvm/llvm-project/pull/119024
>From e3fd6b1d8408439e200622f577451d144ef8f720 Mon Sep 17 00:00:00 2001 From: vb-sc <vladislav.be...@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..74848696963e99 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@-1 {{field has incomplete type 'M' (aka 'void'}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits