[llvm-bugs] [Bug 38633] New: [Formatter/Cpp] Comments before conditions in if else statment are misalligned

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 20 01:58:13 PDT 2018


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

            Bug ID: 38633
           Summary: [Formatter/Cpp] Comments before conditions in if else
                    statment are misalligned
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jolesiak at google.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

I'm not sure whether current behavior is intended, but I think it could be
improved considering how common this pattern is:

Could be:

// description of the condition
if (true) {
  x = 42;
// description of another condition
} else if (true) {
  x = 42;
// description of else
} else {
  x = 42;
}

Current formatting:

// description of the condition
if (true) {
  x = 42;
  // description of another condition
} else if (true) {
  x = 42;
  // description of else
} else {
  x = 42;
}


One drawback, I can think of, of this change would be an incorrect indentation
in the following situation:

Base version:

if (...) {
  x = 42;
  // Assign 43 to x
  x = 43;
} else if (...) {
}

Developer changed to:

if (...) {
  x = 42;
  // Assign 43 to x
  // x = 43; - temporarily comment this line 
} else if (...) {
}

After running clang-format on above code:

if (...) {
  x = 42;
// Assign 43 to x
// x = 43; - temporarily comment this line 
} else if (...) {
}

This would go back to the correct formatting after uncommenting the line, so I
don't think this should be an issue.

-- 
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/20180820/f678eef1/attachment-0001.html>


More information about the llvm-bugs mailing list