[clang] [clang] print correct context for diagnostics suppressed by deduction (PR #125453)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 3 16:02:03 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:

Yeah, it's one of the first things I tried, but it's harder to debug, and harder to be sure of the correctness of the whole thing, as there is a lot of interactions there. This callback scheme is way more straightforward and I like that.

https://github.com/llvm/llvm-project/pull/125453


More information about the cfe-commits mailing list