[PATCH] D126908: [VerifyDiagnosticConsumer] Fix last line being discarded when parsing newline
Vang Thao via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 2 12:36:00 PDT 2022
vangthao created this revision.
Herald added a project: All.
vangthao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
In expected diagnostic checks containing newlines, anything after the last
newline would be discarded since we stop parsing directly after the last newline.
Fix this behavior so that any remaining string after the last newline is
appended instead of ignored.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D126908
Files:
clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
clang/test/SemaCXX/references.cpp
Index: clang/test/SemaCXX/references.cpp
===================================================================
--- clang/test/SemaCXX/references.cpp
+++ clang/test/SemaCXX/references.cpp
@@ -90,7 +90,7 @@
int& okay; // expected-note{{reference member 'okay' will never be initialized}}
};
-struct C : B, A { }; // expected-warning {{direct base 'A' is inaccessible due to ambiguity:\n struct C -> struct B -> struct A\nstruct C -> struct A}}
+struct C : B, A { }; // expected-warning {{direct base 'A' is inaccessible due to ambiguity:\n struct C -> struct B -> struct A\n struct C -> struct A}}
void test7(C& c) {
A& a1 = c; // expected-error {{ambiguous conversion from derived class 'C' to base class 'A':}}
Index: clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
===================================================================
--- clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -631,11 +631,18 @@
StringRef Content(ContentBegin, ContentEnd-ContentBegin);
size_t CPos = 0;
size_t FPos;
+ bool Append = false;
while ((FPos = Content.find(NewlineStr, CPos)) != StringRef::npos) {
D.Text += Content.substr(CPos, FPos-CPos);
D.Text += '\n';
CPos = FPos + NewlineStr.size();
+ Append = true;
}
+ // Previous while loop did not add line after final newline. If there is
+ // more text after the newline, append it here.
+ if (Append && CPos != Content.size())
+ D.Text += Content.substr(CPos, Content.size());
+
if (D.Text.empty())
D.Text.assign(ContentBegin, ContentEnd);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126908.433845.patch
Type: text/x-patch
Size: 1630 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220602/8379741d/attachment.bin>
More information about the cfe-commits
mailing list