LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 19325 - clang-format is not idempotent / misaligns trailing comments
Summary: clang-format is not idempotent / misaligns trailing comments
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: Formatter (show other bugs)
Version: trunk
Hardware: Macintosh MacOS X
: P normal
Assignee: Alexander Kornienko
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-03 09:48 PDT by Max Horn
Modified: 2014-04-17 11:13 PDT (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Max Horn 2014-04-03 09:48:55 PDT
Running clang-format should ideally idempotent, i.e. if I run it,
then run it again, the results of the first and second run should
be identical.

This is currently not the case in the following example:

-- 8< --
int test() {
  int foobar = 0; /* comment */
  int foo = 0;    /* comment */
  int bar = 0;    /* this is a multiline comment
                     and the later vars are shorter */
  int qux = 0;    /* comment */
}
-- 8< --

After running clang-format --style=LLVM on this, you get this:
-- 8< --
int test() {
  int foobar = 0; /* comment */
  int foo = 0;    /* comment */
  int bar = 0;    /* this is a multiline comment
                  and the later vars are shorter */
  int qux = 0; /* comment */
}
-- 8< --

Each run, the line before variable qux gets a little bit less indented. After enough, the process finally stabilizes at this version:
-- 8< --
int test() {
  int foobar = 0; /* comment */
  int foo = 0;    /* comment */
  int bar = 0;    /* this is a multiline comment
and the later vars are shorter */
  int qux = 0; /* comment */
}
-- 8< --

I am using clang SVN revision 205521, llvm rev 205525, on Mac OS X 10.8.5.
Comment 1 Daniel Jasper 2014-04-03 09:52:01 PDT
I can reproduce the behavior. Alex, can you take a look?
Comment 2 Alexander Kornienko 2014-04-15 03:53:08 PDT
Yes, that's weird, will take a look at it today.
Comment 3 Alexander Kornienko 2014-04-17 11:13:39 PDT
Fixed in r206472.