@@ -2751,12 +2751,16 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
2751
2751
line_col = source_mgr.getPresumedLineAndColumnForLoc (source_loc);
2752
2752
}
2753
2753
2754
- if (line_col.first != 0 ) {
2754
+ bool use_fixits = false ;
2755
+ std::string formatted_text;
2756
+ if (!line_col.first ) {
2757
+ formatted_text = text.str ();
2758
+ use_fixits = false ;
2759
+ } else {
2755
2760
ANSIColorStringStream os (m_colorize);
2756
2761
2757
2762
// Determine what kind of diagnostic we're emitting, and whether
2758
2763
// we want to use its fixits:
2759
- bool use_fixits = false ;
2760
2764
llvm::SourceMgr::DiagKind source_mgr_kind;
2761
2765
switch (info.Kind ) {
2762
2766
case swift::DiagnosticKind::Error:
@@ -2809,28 +2813,15 @@ class StoringDiagnosticConsumer : public swift::DiagnosticConsumer {
2809
2813
ranges, fix_its);
2810
2814
source_mgr.getLLVMSourceMgr ().PrintMessage (os, message);
2811
2815
2812
- // Use the llvm::raw_string_ostream::str() accessor as it will
2813
- // flush the stream into our "message" and return us a reference
2814
- // to "message".
2815
- std::string &message_ref = os.str ();
2816
-
2817
- if (message_ref.empty ())
2818
- m_raw_diagnostics.push_back (RawDiagnostic (
2819
- std::string (text), info.Kind , bufferName, bufferID, line_col.first ,
2820
- line_col.second ,
2821
- use_fixits ? info.FixIts
2822
- : llvm::ArrayRef<swift::Diagnostic::FixIt>()));
2823
- else
2824
- m_raw_diagnostics.push_back (RawDiagnostic (
2825
- message_ref, info.Kind , bufferName, bufferID, line_col.first ,
2826
- line_col.second ,
2827
- use_fixits ? info.FixIts
2828
- : llvm::ArrayRef<swift::Diagnostic::FixIt>()));
2829
- } else {
2830
- m_raw_diagnostics.push_back (RawDiagnostic (
2831
- std::string (text), info.Kind , bufferName, bufferID, line_col.first ,
2832
- line_col.second , llvm::ArrayRef<swift::Diagnostic::FixIt>()));
2816
+ // str() implicitly flushes the stram.
2817
+ std::string &s = os.str ();
2818
+ formatted_text = !s.empty () ? std::move (s) : std::string (text);
2833
2819
}
2820
+ m_raw_diagnostics.push_back (
2821
+ {formatted_text, info.Kind , bufferName, bufferID, line_col.first ,
2822
+ line_col.second ,
2823
+ use_fixits ? info.FixIts
2824
+ : llvm::ArrayRef<swift::Diagnostic::FixIt>()});
2834
2825
2835
2826
if (info.Kind == swift::DiagnosticKind::Error)
2836
2827
m_num_errors++;
0 commit comments