[llvm-bugs] [Bug 32969] New: clang-format breaks array initializer in unexpected places

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 8 10:01:26 PDT 2017


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

            Bug ID: 32969
           Summary: clang-format breaks array initializer in unexpected
                    places
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: lukasza at chromium.org
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

Given the following (manually formatted) snippet...

bool IsBlacklistedInstanceMethodName(llvm::StringRef name) {
  static const char* kBlacklistedNames[] = {
      // We should avoid renaming the method names listed below, because
      // 1. They are used in templated code (e.g. in <algorithms>)
      // 2. They (begin+end) are used in range-based for syntax sugar
      //    - for (auto x : foo) { ... }  // <- foo.begin() will be called.
      "begin", "end", "rbegin", "rend", "lock", "unlock", "try_lock",

      // https://crbug.com/672902: Should not rewrite names that mimick methods
      // from std library.
      "at", "back", "clear" "empty", "erase", "find", "front", "insert",
      "length", "size", "swap",
  };
  for (const auto& b : kBlacklistedNames) {
    if (name == b)
      return true;
  }
  return false;
}

clang-format reformats it to:

bool IsBlacklistedInstanceMethodName(llvm::StringRef name) {
  static const char* kBlacklistedNames[] = {
      // We should avoid renaming the method names listed below, because
      // 1. They are used in templated code (e.g. in <algorithms>)
      // 2. They (begin+end) are used in range-based for syntax sugar
      //    - for (auto x : foo) { ... }  // <- foo.begin() will be called.
      "begin", "end", "rbegin", "rend", "lock", "unlock", "try_lock",

      // https://crbug.com/672902: Should not rewrite names that mimick methods
      // from std library.
      "at", "back",
      "clear"
      "empty",
      "erase", "find", "front", "insert", "length", "size", "swap",
  };
  for (const auto& b : kBlacklistedNames) {
    if (name == b)
      return true;
  }
  return false;
}

I am rather surprised that 1) any reformatting is needed at all, 2) that
results take more lines than the original formatting, 3) that the line breaks
seem randomly placed (e.g. *why* after "back", and "clear" and "empty", but not
after "at" or "erase").

-- 
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/20170508/fab43ce8/attachment.html>


More information about the llvm-bugs mailing list