diff options
Diffstat (limited to 'lib/Sema/Sema.cpp')
-rw-r--r-- | lib/Sema/Sema.cpp | 71 |
1 files changed, 32 insertions, 39 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index c3b162031b..fcdfcace0c 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -673,12 +673,17 @@ NamedDecl *Sema::getCurFunctionOrMethodDecl() { return 0; } -Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() { - if (!isActive()) - return; - - if (llvm::Optional<TemplateDeductionInfo*> Info = SemaRef.isSFINAEContext()) { - switch (DiagnosticIDs::getDiagnosticSFINAEResponse(getDiagID())) { +void Sema::EmitCurrentDiagnostic(unsigned DiagID) { + // FIXME: It doesn't make sense to me that DiagID is an incoming argument here + // and yet we also use the current diag ID on the DiagnosticsEngine. This has + // been made more painfully obvious by the refactor that introduced this + // function, but it is possible that the incoming argument can be + // eliminnated. If it truly cannot be (for example, there is some reentrancy + // issue I am not seeing yet), then there should at least be a clarifying + // comment somewhere. + if (llvm::Optional<TemplateDeductionInfo*> Info = isSFINAEContext()) { + switch (DiagnosticIDs::getDiagnosticSFINAEResponse( + Diags.getCurrentDiagID())) { case DiagnosticIDs::SFINAE_Report: // We'll report the diagnostic below. break; @@ -686,10 +691,9 @@ Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() { case DiagnosticIDs::SFINAE_SubstitutionFailure: // Count this failure so that we know that template argument deduction // has failed. - ++SemaRef.NumSFINAEErrors; - SemaRef.Diags.setLastDiagnosticIgnored(); - SemaRef.Diags.Clear(); - Clear(); + ++NumSFINAEErrors; + Diags.setLastDiagnosticIgnored(); + Diags.Clear(); return; case DiagnosticIDs::SFINAE_AccessControl: { @@ -697,52 +701,47 @@ Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() { // Additionally, the AccessCheckingSFINAE flag can be used to temporarily // make access control a part of SFINAE for the purposes of checking // type traits. - if (!SemaRef.AccessCheckingSFINAE && - !SemaRef.getLangOpts().CPlusPlus0x) + if (!AccessCheckingSFINAE && !getLangOpts().CPlusPlus0x) break; - SourceLocation Loc = getLocation(); + SourceLocation Loc = Diags.getCurrentDiagLoc(); // Suppress this diagnostic. - ++SemaRef.NumSFINAEErrors; - SemaRef.Diags.setLastDiagnosticIgnored(); - SemaRef.Diags.Clear(); - Clear(); + ++NumSFINAEErrors; + Diags.setLastDiagnosticIgnored(); + Diags.Clear(); // Now the diagnostic state is clear, produce a C++98 compatibility // warning. - SemaRef.Diag(Loc, diag::warn_cxx98_compat_sfinae_access_control); + Diag(Loc, diag::warn_cxx98_compat_sfinae_access_control); // The last diagnostic which Sema produced was ignored. Suppress any // notes attached to it. - SemaRef.Diags.setLastDiagnosticIgnored(); + Diags.setLastDiagnosticIgnored(); return; } case DiagnosticIDs::SFINAE_Suppress: // Make a copy of this suppressed diagnostic and store it with the // template-deduction information; - FlushCounts(); - Diagnostic DiagInfo(&SemaRef.Diags); + Diagnostic DiagInfo(&Diags); if (*Info) (*Info)->addSuppressedDiagnostic(DiagInfo.getLocation(), - PartialDiagnostic(DiagInfo, - SemaRef.Context.getDiagAllocator())); + PartialDiagnostic(DiagInfo,Context.getDiagAllocator())); // Suppress this diagnostic. - SemaRef.Diags.setLastDiagnosticIgnored(); - SemaRef.Diags.Clear(); - Clear(); + Diags.setLastDiagnosticIgnored(); + Diags.Clear(); return; } } // Set up the context's printing policy based on our current state. - SemaRef.Context.setPrintingPolicy(SemaRef.getPrintingPolicy()); + Context.setPrintingPolicy(getPrintingPolicy()); // Emit the diagnostic. - if (!this->Emit()) + if (!Diags.EmitCurrentDiagnostic()) return; // If this is not a note, and we're in a template instantiation @@ -750,20 +749,14 @@ Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() { // we emitted an error, print a template instantiation // backtrace. if (!DiagnosticIDs::isBuiltinNote(DiagID) && - !SemaRef.ActiveTemplateInstantiations.empty() && - SemaRef.ActiveTemplateInstantiations.back() - != SemaRef.LastTemplateInstantiationErrorContext) { - SemaRef.PrintInstantiationStack(); - SemaRef.LastTemplateInstantiationErrorContext - = SemaRef.ActiveTemplateInstantiations.back(); + !ActiveTemplateInstantiations.empty() && + ActiveTemplateInstantiations.back() + != LastTemplateInstantiationErrorContext) { + PrintInstantiationStack(); + LastTemplateInstantiationErrorContext = ActiveTemplateInstantiations.back(); } } -Sema::SemaDiagnosticBuilder Sema::Diag(SourceLocation Loc, unsigned DiagID) { - DiagnosticBuilder DB = Diags.Report(Loc, DiagID); - return SemaDiagnosticBuilder(DB, *this, DiagID); -} - Sema::SemaDiagnosticBuilder Sema::Diag(SourceLocation Loc, const PartialDiagnostic& PD) { SemaDiagnosticBuilder Builder(Diag(Loc, PD.getDiagID())); |