================ @@ -18324,6 +18324,47 @@ bool Sema::CheckOverridingFunctionAttributes(const CXXMethodDecl *New, return true; } + // Virtual overrides: check for matching effects. + const auto OldFX = Old->getFunctionEffects(); + const auto NewFX = New->getFunctionEffects(); + + if (OldFX != NewFX) { + const auto Diffs = FunctionEffectSet::differences(OldFX, NewFX); + bool AnyDiags = false; + + for (const auto &Item : Diffs) { + const FunctionEffect &Effect = Item.first; + const bool Adding = Item.second; + switch (Effect.diagnoseMethodOverride(Adding, *Old, OldFX, *New, NewFX)) { + case FunctionEffect::OverrideResult::Ignore: + break; + case FunctionEffect::OverrideResult::Warn: + Diag(New->getLocation(), diag::warn_mismatched_func_effect_override) + << Effect.name(); + Diag(Old->getLocation(), diag::note_overridden_virtual_function); + // TODO: It would be nice to have a FIXIT here! + AnyDiags = true; + break; + case FunctionEffect::OverrideResult::Propagate: { + auto MergedFX = FunctionEffectSet::getUnion(Context, OldFX, NewFX); + + FunctionProtoType::ExtProtoInfo EPI = NewFT->getExtProtoInfo(); + EPI.FunctionEffects = MergedFX; + QualType ModQT = Context.getFunctionType(NewFT->getReturnType(), + NewFT->getParamTypes(), EPI); + + // TODO: It's ugly to be mutating the incoming const method. It is + // mutable in the calling function, though. There is also the + // possibility here that we are discarding some other sort of sugar on + // the method's type. + const_cast<CXXMethodDecl *>(New)->setType(ModQT); ---------------- Sirraide wrote:
Yeah, this seems very scuffed to me as well; `New` should probably be a non-`const` pointer (which may have to propagate up to the callers of this function if need be; doing so seems fine as this happens as part of function declaration merging, so we’re changing `New` anyway). https://github.com/llvm/llvm-project/pull/84983 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits