@@ -2685,10 +2685,23 @@ QualType Sema::BuildFunctionType(QualType T,
26852685 return Context.getFunctionType (T, ParamTypes, EPI);
26862686}
26872687
2688- QualType Sema::BuildMemberPointerType (QualType T,
2689- NestedNameSpecifier *Qualifier,
2688+ QualType Sema::BuildMemberPointerType (QualType T, const CXXScopeSpec &SS,
26902689 CXXRecordDecl *Cls, SourceLocation Loc,
26912690 DeclarationName Entity) {
2691+ if (!Cls && !isDependentScopeSpecifier (SS)) {
2692+ Cls = dyn_cast_or_null<CXXRecordDecl>(computeDeclContext (SS));
2693+ if (!Cls) {
2694+ auto D =
2695+ Diag (SS.getBeginLoc (), diag::err_illegal_decl_mempointer_in_nonclass)
2696+ << SS.getRange ();
2697+ if (const IdentifierInfo *II = Entity.getAsIdentifierInfo ())
2698+ D << II;
2699+ else
2700+ D << " member pointer" ;
2701+ return QualType ();
2702+ }
2703+ }
2704+
26922705 // Verify that we're not building a pointer to pointer to function with
26932706 // exception specification.
26942707 if (CheckDistantExceptionSpec (T)) {
@@ -2730,7 +2743,7 @@ QualType Sema::BuildMemberPointerType(QualType T,
27302743 if (T->isFunctionType ())
27312744 adjustMemberFunctionCC (T, /* HasThisPointer=*/ true , IsCtorOrDtor, Loc);
27322745
2733- return Context.getMemberPointerType (T, Qualifier , Cls);
2746+ return Context.getMemberPointerType (T, SS. getScopeRep () , Cls);
27342747}
27352748
27362749QualType Sema::BuildBlockPointerType (QualType T,
@@ -5344,20 +5357,9 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
53445357 // Avoid emitting extra errors if we already errored on the scope.
53455358 D.setInvalidType (true );
53465359 AreDeclaratorChunksValid = false ;
5347- } else if (auto *RD =
5348- dyn_cast_or_null<CXXRecordDecl>(S.computeDeclContext (SS));
5349- RD || S.isDependentScopeSpecifier (SS)) {
5350- T = S.BuildMemberPointerType (T, SS.getScopeRep (), RD, DeclType.Loc ,
5351- D.getIdentifier ());
53525360 } else {
5353- S.Diag (DeclType.Mem .Scope ().getBeginLoc (),
5354- diag::err_illegal_decl_mempointer_in_nonclass)
5355- << (D.getIdentifier () ? D.getIdentifier ()->getName () : " type name" )
5356- << DeclType.Mem .Scope ().getRange ();
5357- D.setInvalidType (true );
5358- AreDeclaratorChunksValid = false ;
5359- // FIXME: Maybe we could model these as as a MemberPointerType with a
5360- // non-dependent, non-class qualifier anyway.
5361+ T = S.BuildMemberPointerType (T, SS, /* Cls=*/ nullptr , DeclType.Loc ,
5362+ D.getIdentifier ());
53615363 }
53625364
53635365 if (T.isNull ()) {
@@ -9255,10 +9257,10 @@ bool Sema::RequireCompleteTypeImpl(SourceLocation Loc, QualType T,
92559257 // "Can't ask whether a dependent type is complete");
92569258
92579259 if (const MemberPointerType *MPTy = T->getAs <MemberPointerType>()) {
9258- if (! MPTy->getQualifier ()-> isDependent ()) {
9259- QualType T = Context. getTypeDeclType (MPTy-> getMostRecentCXXRecordDecl ());
9260- if ( getLangOpts (). CompleteMemberPointers &&
9261- !MPTy-> getMostRecentCXXRecordDecl () ->isBeingDefined () &&
9260+ if (CXXRecordDecl *RD = MPTy->getMostRecentCXXRecordDecl ();
9261+ RD && !RD-> isDependentType ()) {
9262+ QualType T = Context. getTypeDeclType (RD);
9263+ if ( getLangOpts (). CompleteMemberPointers && !RD ->isBeingDefined () &&
92629264 RequireCompleteType (Loc, T, Kind, diag::err_memptr_incomplete))
92639265 return true ;
92649266
0 commit comments