idlecode created this revision. idlecode added a subscriber: cfe-commits. Herald added a subscriber: klimek.
During clang-format source lexing >> and << operators are split and treated as two less/greater operators but column position of following tokens was not adjusted accordingly. https://reviews.llvm.org/D25439 Files: lib/Format/FormatTokenLexer.cpp test/Format/bitshift-operator-width.cpp Index: test/Format/bitshift-operator-width.cpp =================================================================== --- /dev/null +++ test/Format/bitshift-operator-width.cpp @@ -0,0 +1,13 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -style=LLVM \ +// RUN: | FileCheck -strict-whitespace %s + +// CHECK: {{^int a = 1 << 2; /\* foo$}} +// CHECK: {{^ bar \*/$}} +int a = 1 << 2; /* foo + bar */ + +// CHECK: {{^int b = 256 >> 2; /\* foo$}} +// CHECK: {{^ bar \*/$}} +int b = 256 >> 2; /* foo + bar */ + Index: lib/Format/FormatTokenLexer.cpp =================================================================== --- lib/Format/FormatTokenLexer.cpp +++ lib/Format/FormatTokenLexer.cpp @@ -525,10 +525,12 @@ } else if (FormatTok->Tok.is(tok::greatergreater)) { FormatTok->Tok.setKind(tok::greater); FormatTok->TokenText = FormatTok->TokenText.substr(0, 1); + Column += 1; StateStack.push(LexerState::TOKEN_STASHED); } else if (FormatTok->Tok.is(tok::lessless)) { FormatTok->Tok.setKind(tok::less); FormatTok->TokenText = FormatTok->TokenText.substr(0, 1); + Column += 1; StateStack.push(LexerState::TOKEN_STASHED); }
Index: test/Format/bitshift-operator-width.cpp =================================================================== --- /dev/null +++ test/Format/bitshift-operator-width.cpp @@ -0,0 +1,13 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -style=LLVM \ +// RUN: | FileCheck -strict-whitespace %s + +// CHECK: {{^int a = 1 << 2; /\* foo$}} +// CHECK: {{^ bar \*/$}} +int a = 1 << 2; /* foo + bar */ + +// CHECK: {{^int b = 256 >> 2; /\* foo$}} +// CHECK: {{^ bar \*/$}} +int b = 256 >> 2; /* foo + bar */ + Index: lib/Format/FormatTokenLexer.cpp =================================================================== --- lib/Format/FormatTokenLexer.cpp +++ lib/Format/FormatTokenLexer.cpp @@ -525,10 +525,12 @@ } else if (FormatTok->Tok.is(tok::greatergreater)) { FormatTok->Tok.setKind(tok::greater); FormatTok->TokenText = FormatTok->TokenText.substr(0, 1); + Column += 1; StateStack.push(LexerState::TOKEN_STASHED); } else if (FormatTok->Tok.is(tok::lessless)) { FormatTok->Tok.setKind(tok::less); FormatTok->TokenText = FormatTok->TokenText.substr(0, 1); + Column += 1; StateStack.push(LexerState::TOKEN_STASHED); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits