[clang] [clang] print correct context for diagnostics suppressed by deduction (PR #125453)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 19 03:18:48 PST 2025
================
@@ -1654,11 +1654,20 @@ void Sema::EmitDiagnostic(unsigned DiagID, const DiagnosticBuilder &DB) {
}
case DiagnosticIDs::SFINAE_Suppress:
+ if (DiagnosticsEngine::Level Level = getDiagnostics().getDiagnosticLevel(
+ DiagInfo.getID(), DiagInfo.getLocation());
+ Level == DiagnosticsEngine::Ignored)
+ return;
// Make a copy of this suppressed diagnostic and store it with the
// template-deduction information;
if (*Info) {
- (*Info)->addSuppressedDiagnostic(DiagInfo.getLocation(),
- PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
+ (*Info)->addSuppressedDiagnostic(
+ DiagInfo.getLocation(),
+ PartialDiagnostic(DiagInfo, Context.getDiagAllocator()));
+ if (!Diags.getDiagnosticIDs()->isNote(DiagID))
+ PrintContextStack([Info](SourceLocation Loc, PartialDiagnostic PD) {
+ (*Info)->addSuppressedDiagnostic(Loc, std::move(PD));
+ });
----------------
mizvekov wrote:
We weren't generating the context stack notes from the point the error was issued and saved, we would instead defer these notes to the later point where the saved error was emitted, which is when the declaration being deduced was actually used.
This patch saves the context note from the point the error was issued, and stops emitting the context notes from the point of decl use.
So I don't see how we could emit duplicate diagnostics here, other than pre-existing issues where the error itself or some of its manually emitted notes are redundant with some context notes.
https://github.com/llvm/llvm-project/pull/125453
More information about the cfe-commits
mailing list