[llvm-bugs] [Bug 31909] formatter doesn't correctly count length of Unicode codepoints

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 22 08:09:52 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=31909

Alexander Kornienko <alexfh at google.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alexfh at google.com
         Resolution|---                         |WONTFIX
             Status|NEW                         |RESOLVED

--- Comment #1 from Alexander Kornienko <alexfh at google.com> ---
clang-format does count the ellipsis for a single character with a width of 1
column:
$ cat /tmp/q.cc 
/*
00000000011111111112222222222333333333344444444445555555555666666666677777777778
12345678901234567890123456789012345678901234567890123456789012345678901234567890
*/
// … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … …
… … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … …
$ clang-format -style=google /tmp/q.cc 
/*
00000000011111111112222222222333333333344444444445555555555666666666677777777778
12345678901234567890123456789012345678901234567890123456789012345678901234567890
*/
// … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … …
…
// … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … …


Now getting back to your input. Its current formatting is:
$ cat /tmp/q.cc 
#define MACRO() \
    int test; \
    // This is my test comment in a macro… This is my test comment in a macro…
\
    // This is my test comment in a macro. This is my test comment in a macro.
$ clang-format -style=google /tmp/q.cc 
#define MACRO() \
  int test;     \
  // This is my test comment in a macro… This is my test comment in a macro… \
    // This is my test comment in a macro. This is my test comment in a macro.


What is going on here has nothing to do with the ellipsis character:
$ cat /tmp/q.cc 
#define MACRO() \
    int test; \
    // This is my test comment in a macro. This is my test comment in a macro.
\
    // This is my test comment in a macro. This is my test comment in a macro.
$ clang-format -style=google /tmp/q.cc 
#define MACRO() \
  int test;     \
  // This is my test comment in a macro. This is my test comment in a macro. \
    // This is my test comment in a macro. This is my test comment in a macro.


The reason is that there's only a single comment here - with an escaped newline
and the `    //` characters in the middle. Clang-format just doesn't touch the
contents of comments and string literals containing escaped newlines:
$ cat /tmp/q.cc 
/*
00000000011111111112222222222333333333344444444445555555555666666666677777777778
12345678901234567890123456789012345678901234567890123456789012345678901234567890
*/
  // aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp qqq rrr
sss ttt uuu vvv www \
  // AAA BBB CCC DDD EEE FFF GGG HHH III JJJ KKK LLL MMM NNN OOO PPP QQQ RRR
SSS TTT UUU VVV WWW
$ clang-format -style=google /tmp/q.cc 
/*
00000000011111111112222222222333333333344444444445555555555666666666677777777778
12345678901234567890123456789012345678901234567890123456789012345678901234567890
*/
// aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp qqq rrr sss
ttt uuu vvv www \
  // AAA BBB CCC DDD EEE FFF GGG HHH III JJJ KKK LLL MMM NNN OOO PPP QQQ RRR
SSS TTT UUU VVV WWW

This is intended behavior, I believe.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180322/d8ffbe5b/attachment.html>


More information about the llvm-bugs mailing list