From 8b3da1112e65706cf5dda55ecd03b514a05d837c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20Gr=C3=A4sman?= Date: Mon, 3 Oct 2022 17:07:18 +0200 Subject: [PATCH] Better support CRLF line endings in custom lexer Running the tests/cxx/comment_pragmas.cc test on Windows fails saying that is not diagnosed correctly. Turns out to be because our custom lexer for GNU @headername comment directives did not respect Windows line endings, and failed properly identify the @headername. Match on both CR and LF when attempting to find end of line. --- iwyu_lexer_utils.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iwyu_lexer_utils.cc b/iwyu_lexer_utils.cc index bd35324..e08612e 100644 --- a/iwyu_lexer_utils.cc +++ b/iwyu_lexer_utils.cc @@ -49,7 +49,7 @@ const char* SourceManagerCharacterDataGetter::GetCharacterData( StringRef GetSourceTextUntilEndOfLine( SourceLocation start_loc, const CharacterDataGetterInterface& data_getter) { const char* data = data_getter.GetCharacterData(start_loc); - const char* line_end = strchr(data, '\n'); + const char* line_end = strpbrk(data, "\r\n"); if (!line_end) return data; return StringRef(data, line_end - data);