From 0948fc85aa99a8fd193d2d66a517e31b8b639f20 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Thu, 20 Feb 2025 08:50:03 -0300 Subject: [clang] print correct context for diagnostics suppressed by deduction (#125453) This patch makes it so the correct instantiation context is printed for diagnostics suppessed by template argument deduction. The context is saved along with the suppressed diagnostic, and when the declaration they were attached to becomes used, we print the correct context, instead of whatever context was at this point. --- clang/lib/Sema/Sema.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'clang/lib/Sema/Sema.cpp') diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index afd1d7a..145cda6 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -1655,11 +1655,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)); + }); } // Suppress this diagnostic. -- cgit v1.1