@@ -3070,18 +3070,24 @@ bool Sema::FindAllocationFunctions(
3070
3070
Filter.done ();
3071
3071
}
3072
3072
3073
+ auto GetRedeclContext = [](Decl *D) {
3074
+ return D->getDeclContext ()->getRedeclContext ();
3075
+ };
3076
+
3077
+ DeclContext *OperatorNewContext = GetRedeclContext (OperatorNew);
3078
+
3073
3079
bool FoundGlobalDelete = FoundDelete.empty ();
3074
3080
bool IsClassScopedTypeAwareNew =
3075
3081
isTypeAwareAllocation (IAP.PassTypeIdentity ) &&
3076
- OperatorNew-> getDeclContext () ->isRecord ();
3082
+ OperatorNewContext ->isRecord ();
3077
3083
auto DiagnoseMissingTypeAwareCleanupOperator = [&](bool IsPlacementOperator) {
3078
3084
assert (isTypeAwareAllocation (IAP.PassTypeIdentity ));
3079
3085
if (Diagnose) {
3080
3086
Diag (StartLoc, diag::err_mismatching_type_aware_cleanup_deallocator)
3081
3087
<< OperatorNew->getDeclName () << IsPlacementOperator << DeleteName;
3082
3088
Diag (OperatorNew->getLocation (), diag::note_type_aware_operator_declared)
3083
3089
<< OperatorNew->isTypeAwareOperatorNewOrDelete ()
3084
- << OperatorNew->getDeclName () << OperatorNew-> getDeclContext () ;
3090
+ << OperatorNew->getDeclName () << OperatorNewContext ;
3085
3091
}
3086
3092
};
3087
3093
if (IsClassScopedTypeAwareNew && FoundDelete.empty ()) {
@@ -3224,15 +3230,15 @@ bool Sema::FindAllocationFunctions(
3224
3230
// deallocation function will be called.
3225
3231
if (Matches.size () == 1 ) {
3226
3232
OperatorDelete = Matches[0 ].second ;
3233
+ DeclContext *OperatorDeleteContext = GetRedeclContext (OperatorDelete);
3227
3234
bool FoundTypeAwareOperator =
3228
3235
OperatorDelete->isTypeAwareOperatorNewOrDelete () ||
3229
3236
OperatorNew->isTypeAwareOperatorNewOrDelete ();
3230
3237
if (Diagnose && FoundTypeAwareOperator) {
3231
3238
bool MismatchedTypeAwareness =
3232
3239
OperatorDelete->isTypeAwareOperatorNewOrDelete () !=
3233
3240
OperatorNew->isTypeAwareOperatorNewOrDelete ();
3234
- bool MismatchedContext =
3235
- OperatorDelete->getDeclContext () != OperatorNew->getDeclContext ();
3241
+ bool MismatchedContext = OperatorDeleteContext != OperatorNewContext;
3236
3242
if (MismatchedTypeAwareness || MismatchedContext) {
3237
3243
FunctionDecl *Operators[] = {OperatorDelete, OperatorNew};
3238
3244
bool TypeAwareOperatorIndex =
@@ -3241,16 +3247,15 @@ bool Sema::FindAllocationFunctions(
3241
3247
<< Operators[TypeAwareOperatorIndex]->getDeclName ()
3242
3248
<< isPlacementNew
3243
3249
<< Operators[!TypeAwareOperatorIndex]->getDeclName ()
3244
- << Operators[TypeAwareOperatorIndex]-> getDeclContext ( );
3250
+ << GetRedeclContext ( Operators[TypeAwareOperatorIndex]);
3245
3251
Diag (OperatorNew->getLocation (),
3246
3252
diag::note_type_aware_operator_declared)
3247
3253
<< OperatorNew->isTypeAwareOperatorNewOrDelete ()
3248
- << OperatorNew->getDeclName () << OperatorNew-> getDeclContext () ;
3254
+ << OperatorNew->getDeclName () << OperatorNewContext ;
3249
3255
Diag (OperatorDelete->getLocation (),
3250
3256
diag::note_type_aware_operator_declared)
3251
3257
<< OperatorDelete->isTypeAwareOperatorNewOrDelete ()
3252
- << OperatorDelete->getDeclName ()
3253
- << OperatorDelete->getDeclContext ();
3258
+ << OperatorDelete->getDeclName () << OperatorDeleteContext;
3254
3259
}
3255
3260
}
3256
3261
0 commit comments