From 5bb5e4ad9d8ed8ac59ae15c716fea9b34a88fd59 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 12 Oct 2010 23:32:35 +0000 Subject: Introduce support for emitting diagnostics (warnings + their notes) that are suppressed during template argument deduction. This change queues diagnostics computed during template argument deduction. Then, if the resulting function template specialization or partial specialization is chosen by overload resolution or partial ordering (respectively), we will emit the queued diagnostics at that point. This addresses most of PR6784. However, the check for unnamed/local template arguments (which existed before this change) is still only skin-deep, and needs to be extended to look deeper into types. It must be improved to finish PR6784. llvm-svn: 116373 --- clang/lib/Sema/Sema.cpp | 55 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'clang/lib/Sema/Sema.cpp') diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index a0046a2caa1..1b3572a6498 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -19,6 +19,7 @@ #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/APFloat.h" #include "clang/Sema/CXXFieldCollector.h" +#include "clang/Sema/TemplateDeduction.h" #include "clang/Sema/ExternalSemaSource.h" #include "clang/Sema/ObjCMethodList.h" #include "clang/Sema/PrettyDeclStackTrace.h" @@ -433,6 +434,41 @@ NamedDecl *Sema::getCurFunctionOrMethodDecl() { } Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() { + if (!isActive()) + return; + + if (TemplateDeductionInfo *Info = SemaRef.isSFINAEContext()) { + switch (Diagnostic::getDiagnosticSFINAEResponse(getDiagID())) { + case Diagnostic::SFINAE_Report: + // Fall through; we'll report the diagnostic below. + break; + + case Diagnostic::SFINAE_SubstitutionFailure: + // Count this failure so that we know that template argument deduction + // has failed. + ++SemaRef.NumSFINAEErrors; + SemaRef.Diags.setLastDiagnosticIgnored(); + SemaRef.Diags.Clear(); + Clear(); + return; + + case Diagnostic::SFINAE_Suppress: + // Make a copy of this suppressed diagnostic and store it with the + // template-deduction information; + DiagnosticInfo DiagInfo(&SemaRef.Diags); + Info->addSuppressedDiagnostic(DiagInfo.getLocation(), + PartialDiagnostic(DiagInfo, + SemaRef.Context.getDiagAllocator())); + + // Suppress this diagnostic. + SemaRef.Diags.setLastDiagnosticIgnored(); + SemaRef.Diags.Clear(); + Clear(); + return; + } + } + + // Emit the diagnostic. if (!this->Emit()) return; @@ -451,25 +487,6 @@ Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() { } Sema::SemaDiagnosticBuilder Sema::Diag(SourceLocation Loc, unsigned DiagID) { - if (isSFINAEContext()) { - switch (Diagnostic::getDiagnosticSFINAEResponse(DiagID)) { - case Diagnostic::SFINAE_Report: - // Fall through; we'll report the diagnostic below. - break; - - case Diagnostic::SFINAE_SubstitutionFailure: - // Count this failure so that we know that template argument deduction - // has failed. - ++NumSFINAEErrors; - // Fall through - - case Diagnostic::SFINAE_Suppress: - // Suppress this diagnostic. - Diags.setLastDiagnosticIgnored(); - return SemaDiagnosticBuilder(*this); - } - } - DiagnosticBuilder DB = Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID); return SemaDiagnosticBuilder(DB, *this, DiagID); } -- cgit v1.2.3