[llvm-bugs] [Bug 39164] New: Already formatted source code is changed on every clang-format run

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 3 08:34:23 PDT 2018


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

            Bug ID: 39164
           Summary: Already formatted source code is changed on every
                    clang-format run
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: vg at glavny.org
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

Created attachment 20954
  --> https://bugs.llvm.org/attachment.cgi?id=20954&action=edit
example of cyclic mutating source code

This code (sample.cpp) is changed on each clang-format run:
> int foo() {
>   // clang-format off
>   #define X 1
>   // clang-format on
>   return (X);
> }

Test run:
> clang-format sample.cpp > result_1.cpp
> clang-format result_1.cpp > result_2.cpp
> clang-format result_2.cpp > result_3.cpp 

Results:
sample.cpp != result_1.cpp
result_2.cpp != result_1.cpp
result_2.cpp == sample.cpp
result_3.cpp != result_2.cpp
result_3.cpp == result_1.cpp

To fix this, need to add one blank line before a preprocessor directive:
> int foo_fixed() {
>   // clang-format off
> 
>   #define X 1
>   // clang-format on
>   return (X);
> }

This behavior has been checked in 6.0 and 7.0 under Linux and Windows.

-- 
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/20181003/ba52be7e/attachment.html>


More information about the llvm-bugs mailing list