@@ -3070,18 +3070,24 @@ bool Sema::FindAllocationFunctions(
30703070 Filter.done ();
30713071 }
30723072
3073+ auto GetRedeclContext = [](Decl *D) {
3074+ return D->getDeclContext ()->getRedeclContext ();
3075+ };
3076+
3077+ DeclContext *OperatorNewContext = GetRedeclContext (OperatorNew);
3078+
30733079 bool FoundGlobalDelete = FoundDelete.empty ();
30743080 bool IsClassScopedTypeAwareNew =
30753081 isTypeAwareAllocation (IAP.PassTypeIdentity ) &&
3076- OperatorNew-> getDeclContext () ->isRecord ();
3082+ OperatorNewContext ->isRecord ();
30773083 auto DiagnoseMissingTypeAwareCleanupOperator = [&](bool IsPlacementOperator) {
30783084 assert (isTypeAwareAllocation (IAP.PassTypeIdentity ));
30793085 if (Diagnose) {
30803086 Diag (StartLoc, diag::err_mismatching_type_aware_cleanup_deallocator)
30813087 << OperatorNew->getDeclName () << IsPlacementOperator << DeleteName;
30823088 Diag (OperatorNew->getLocation (), diag::note_type_aware_operator_declared)
30833089 << OperatorNew->isTypeAwareOperatorNewOrDelete ()
3084- << OperatorNew->getDeclName () << OperatorNew-> getDeclContext () ;
3090+ << OperatorNew->getDeclName () << OperatorNewContext ;
30853091 }
30863092 };
30873093 if (IsClassScopedTypeAwareNew && FoundDelete.empty ()) {
@@ -3224,15 +3230,15 @@ bool Sema::FindAllocationFunctions(
32243230 // deallocation function will be called.
32253231 if (Matches.size () == 1 ) {
32263232 OperatorDelete = Matches[0 ].second ;
3233+ DeclContext *OperatorDeleteContext = GetRedeclContext (OperatorDelete);
32273234 bool FoundTypeAwareOperator =
32283235 OperatorDelete->isTypeAwareOperatorNewOrDelete () ||
32293236 OperatorNew->isTypeAwareOperatorNewOrDelete ();
32303237 if (Diagnose && FoundTypeAwareOperator) {
32313238 bool MismatchedTypeAwareness =
32323239 OperatorDelete->isTypeAwareOperatorNewOrDelete () !=
32333240 OperatorNew->isTypeAwareOperatorNewOrDelete ();
3234- bool MismatchedContext =
3235- OperatorDelete->getDeclContext () != OperatorNew->getDeclContext ();
3241+ bool MismatchedContext = OperatorDeleteContext != OperatorNewContext;
32363242 if (MismatchedTypeAwareness || MismatchedContext) {
32373243 FunctionDecl *Operators[] = {OperatorDelete, OperatorNew};
32383244 bool TypeAwareOperatorIndex =
@@ -3241,16 +3247,15 @@ bool Sema::FindAllocationFunctions(
32413247 << Operators[TypeAwareOperatorIndex]->getDeclName ()
32423248 << isPlacementNew
32433249 << Operators[!TypeAwareOperatorIndex]->getDeclName ()
3244- << Operators[TypeAwareOperatorIndex]-> getDeclContext ( );
3250+ << GetRedeclContext ( Operators[TypeAwareOperatorIndex]);
32453251 Diag (OperatorNew->getLocation (),
32463252 diag::note_type_aware_operator_declared)
32473253 << OperatorNew->isTypeAwareOperatorNewOrDelete ()
3248- << OperatorNew->getDeclName () << OperatorNew-> getDeclContext () ;
3254+ << OperatorNew->getDeclName () << OperatorNewContext ;
32493255 Diag (OperatorDelete->getLocation (),
32503256 diag::note_type_aware_operator_declared)
32513257 << OperatorDelete->isTypeAwareOperatorNewOrDelete ()
3252- << OperatorDelete->getDeclName ()
3253- << OperatorDelete->getDeclContext ();
3258+ << OperatorDelete->getDeclName () << OperatorDeleteContext;
32543259 }
32553260 }
32563261
0 commit comments