File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -1564,7 +1564,7 @@ inline DiagnosticBuilder DiagnosticsEngine::Report(unsigned DiagID) {
1564
1564
// / currently in-flight diagnostic.
1565
1565
class Diagnostic {
1566
1566
const DiagnosticsEngine *DiagObj;
1567
- StringRef StoredDiagMessage;
1567
+ std::optional< StringRef> StoredDiagMessage;
1568
1568
1569
1569
public:
1570
1570
explicit Diagnostic (const DiagnosticsEngine *DO) : DiagObj(DO) {}
Original file line number Diff line number Diff line change @@ -801,8 +801,8 @@ static const char *getTokenDescForDiagnostic(tok::TokenKind Kind) {
801
801
// / array.
802
802
void Diagnostic::
803
803
FormatDiagnostic (SmallVectorImpl<char > &OutStr) const {
804
- if (! StoredDiagMessage.empty ()) {
805
- OutStr.append (StoredDiagMessage. begin (), StoredDiagMessage. end ());
804
+ if (StoredDiagMessage.has_value ()) {
805
+ OutStr.append (StoredDiagMessage-> begin (), StoredDiagMessage-> end ());
806
806
return ;
807
807
}
808
808
Original file line number Diff line number Diff line change 9
9
#include " clang/Basic/Diagnostic.h"
10
10
#include " clang/Basic/DiagnosticError.h"
11
11
#include " clang/Basic/DiagnosticIDs.h"
12
+ #include " clang/Basic/DiagnosticLex.h"
12
13
#include " gtest/gtest.h"
13
14
14
15
using namespace llvm ;
@@ -127,4 +128,26 @@ TEST(DiagnosticTest, diagnosticError) {
127
128
EXPECT_EQ (*Value, std::make_pair (20 , 1 ));
128
129
EXPECT_EQ (Value->first , 20 );
129
130
}
131
+
132
+ TEST (DiagnosticTest, storedDiagEmptyWarning) {
133
+ DiagnosticsEngine Diags (new DiagnosticIDs (), new DiagnosticOptions);
134
+
135
+ class CaptureDiagnosticConsumer : public DiagnosticConsumer {
136
+ public:
137
+ SmallVector<StoredDiagnostic> StoredDiags;
138
+
139
+ void HandleDiagnostic (DiagnosticsEngine::Level level,
140
+ const Diagnostic &Info) override {
141
+ StoredDiags.push_back (StoredDiagnostic (level, Info));
142
+ }
143
+ };
144
+
145
+ CaptureDiagnosticConsumer CaptureConsumer;
146
+ Diags.setClient (&CaptureConsumer, /* ShouldOwnClient=*/ false );
147
+ Diags.Report (diag::pp_hash_warning) << " " ;
148
+ ASSERT_TRUE (CaptureConsumer.StoredDiags .size () == 1 );
149
+
150
+ // Make sure an empty warning can round-trip with \c StoredDiagnostic.
151
+ Diags.Report (CaptureConsumer.StoredDiags .front ());
152
+ }
130
153
}
You can’t perform that action at this time.
0 commit comments