Index: include/clang/AST/DeclCXX.h =================================================================== --- include/clang/AST/DeclCXX.h +++ include/clang/AST/DeclCXX.h @@ -751,6 +751,21 @@ return const_cast(this)->getMostRecentDecl(); } + CXXRecordDecl *getMostRecentNonInjectedDecl() { + CXXRecordDecl *Recent = + static_cast(this)->getMostRecentDecl(); + while (Recent->isInjectedClassName()) { + // FIXME: Does injected class name need to be in the redeclarations chain? + assert(Recent->getPreviousDecl()); + Recent = Recent->getPreviousDecl(); + } + return Recent; + } + + const CXXRecordDecl *getMostRecentNonInjectedDecl() const { + return const_cast(this)->getMostRecentNonInjectedDecl(); + } + CXXRecordDecl *getDefinition() const { // We only need an update if we don't already know which // declaration is the definition. Index: lib/AST/MicrosoftMangle.cpp =================================================================== --- lib/AST/MicrosoftMangle.cpp +++ lib/AST/MicrosoftMangle.cpp @@ -1370,12 +1370,12 @@ const NamedDecl *ND = TA.getAsDecl(); if (isa(ND) || isa(ND)) { mangleMemberDataPointer( - cast(ND->getDeclContext())->getMostRecentDecl(), + cast(ND->getDeclContext())->getMostRecentNonInjectedDecl(), cast(ND)); } else if (const FunctionDecl *FD = dyn_cast(ND)) { const CXXMethodDecl *MD = dyn_cast(FD); if (MD && MD->isInstance()) { - mangleMemberFunctionPointer(MD->getParent()->getMostRecentDecl(), MD); + mangleMemberFunctionPointer(MD->getParent()->getMostRecentNonInjectedDecl(), MD); } else { Out << "$1?"; mangleName(FD); Index: lib/AST/Type.cpp =================================================================== --- lib/AST/Type.cpp +++ lib/AST/Type.cpp @@ -2040,7 +2040,7 @@ return false; // The inheritance attribute might only be present on the most recent // CXXRecordDecl, use that one. - RD = RD->getMostRecentDecl(); + RD = RD->getMostRecentNonInjectedDecl(); // Nothing interesting to do if the inheritance attribute is already set. if (RD->hasAttr()) return false; @@ -3936,5 +3936,5 @@ } CXXRecordDecl *MemberPointerType::getMostRecentCXXRecordDecl() const { - return getClass()->getAsCXXRecordDecl()->getMostRecentDecl(); + return getClass()->getAsCXXRecordDecl()->getMostRecentNonInjectedDecl(); } Index: lib/CodeGen/MicrosoftCXXABI.cpp =================================================================== --- lib/CodeGen/MicrosoftCXXABI.cpp +++ lib/CodeGen/MicrosoftCXXABI.cpp @@ -2733,7 +2733,7 @@ assert(MD->isInstance() && "Member function must not be static!"); CharUnits NonVirtualBaseAdjustment = CharUnits::Zero(); - const CXXRecordDecl *RD = MD->getParent()->getMostRecentDecl(); + const CXXRecordDecl *RD = MD->getParent()->getMostRecentNonInjectedDecl(); CodeGenTypes &Types = CGM.getTypes(); unsigned VBTableIndex = 0; Index: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -7544,7 +7544,7 @@ /// Locks in the inheritance model for the given class and all of its bases. static void assignInheritanceModel(Sema &S, CXXRecordDecl *RD) { - RD = RD->getMostRecentDecl(); + RD = RD->getMostRecentNonInjectedDecl(); if (!RD->hasAttr()) { MSInheritanceAttr::Spelling IM;