[llvm-bugs] [Bug 48710] New: Non-deterministic formatting of preprocessor directives combined with clang-format comments.

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 11 04:42:20 PST 2021


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

            Bug ID: 48710
           Summary: Non-deterministic formatting of preprocessor
                    directives combined with clang-format comments.
           Product: clang
           Version: 11.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nitrix at nitrix.me
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

Hello,

The following code:

==================== example.c ====================
void foo(void) {
    // clang-format off
    #define BAR 42
    // clang-format on
}
===================================================

with the following configuration:

================== .clang-format ==================
---
IndentCaseLabels: 'true'
IndentWidth: '4'

...
===================================================

has non-deterministic behavior. When formatted, the line #2 of example.c with
the `// clang-format off` comments looses its indentation, then, when
formatting is performed again on that output, will re-add the indentation,
effectively toggling back-and-forth.

This is a problem because it constantly generates changes in version-control
for the files affected.

I don't know if the problem is more broad than this, but this is how I was able
to reproduce it.

-- 
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/20210111/59c4aa00/attachment.html>


More information about the llvm-bugs mailing list