Index: lib/Sema/SemaExprMember.cpp =================================================================== --- lib/Sema/SemaExprMember.cpp +++ lib/Sema/SemaExprMember.cpp @@ -90,7 +90,6 @@ /// conservatively answer "yes", in which case some errors will simply /// not be caught until template-instantiation. static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef, - Scope *CurScope, const LookupResult &R) { assert(!R.empty() && (*R.begin())->isCXXClassMember()); @@ -205,6 +204,9 @@ SourceRange Range(Loc); if (SS.isSet()) Range.setBegin(SS.getRange().getBegin()); + // Look through using shadow decls and aliases. + Rep = Rep->getUnderlyingDecl(); + DeclContext *FunctionLevelDC = SemaRef.getFunctionLevelDeclContext(); CXXMethodDecl *Method = dyn_cast(FunctionLevelDC); CXXRecordDecl *ContextClass = Method ? Method->getParent() : nullptr; @@ -237,7 +239,7 @@ SourceLocation TemplateKWLoc, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs) { - switch (ClassifyImplicitMemberAccess(*this, CurScope, R)) { + switch (ClassifyImplicitMemberAccess(*this, R)) { case IMA_Instance: return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, true); Index: lib/Sema/TreeTransform.h =================================================================== --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -8705,8 +8705,18 @@ // If we have neither explicit template arguments, nor the template keyword, // it's a normal declaration name. - if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) + if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) { + // If this resolved to a data member, do member reference semantic analysis + // and possibly form a MemberExpr. + if (NamedDecl *D = R.getAsSingle()) { + D = D->getUnderlyingDecl(); + if (isa(D) || isa(D) || + isa(D)) + return getSema().BuildPossibleImplicitMemberExpr( + SS, SourceLocation(), R, /*TemplateArgs=*/nullptr); + } return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); + } // If we have template arguments, rebuild them, then rebuild the // templateid expression. Index: test/SemaTemplate/instantiate-using-decl.cpp =================================================================== --- test/SemaTemplate/instantiate-using-decl.cpp +++ test/SemaTemplate/instantiate-using-decl.cpp @@ -104,3 +104,26 @@ x.f(); } } + +namespace PR21923 { +struct A { + int member; + void method(); +}; +template +struct B : public T { + using T::member; + using T::method; + static void StaticFun() { + (void)member; // expected-error {{invalid use of member 'member' in static member function}} + (void)B::member; // expected-error {{invalid use of member 'member' in static member function}} + method(); // expected-error {{call to non-static member function without an object argument}} + } + void InstanceFun() { + (void)member; + (void)B::member; + method(); + } +}; +template class B; // expected-note 1 {{requested here}} +}