[PATCH] D20959: [clang-format] make header guard identification stricter (with Lexer).
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 6 01:59:23 PDT 2016
ioeric added inline comments.
================
Comment at: lib/Format/Format.cpp:1500
@@ +1499,3 @@
+ // Get the first token.
+ Lex.LexFromRawLexer(Tok);
+ skipComments(Lex, Tok);
----------------
djasper wrote:
> Can this go wrong? Maybe in an empty file?
Added a test case for empty file.
If the code is empty, Tok will be `tok::eof`, which would leave `MinInsertionOffset` as `Code.size()`.
But the program does fail when we insert at the end of code that does not end with '\n'. We always +1 when we calculate the offset for each line (in the for-loop on Lines); however, the last line does not necessarily end with '\n', which makes offset exceed code size. I will fix this in a follow-up patch.
http://reviews.llvm.org/D20959
More information about the cfe-commits
mailing list