[llvm-bugs] [Bug 47545] New: clang-formatter incorrectly breaks the line for constexpr lambda call initializing a variable

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 16 06:43:37 PDT 2020


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

            Bug ID: 47545
           Summary: clang-formatter incorrectly breaks the line for
                    constexpr lambda call initializing a variable
           Product: clang
           Version: 10.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: andrei at ethereum.org
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

$ clang-format --version
Ubuntu clang-format version
10.0.1-++20200708123514+ef32c611aa2-1~exp1~20200707224111.189 

The code that initializes a variable using curly braces and a call to inline
_constexpr_ lambda is formatted incorrectly:

$ echo "int i{[]() constexpr noexcept { std::cout << "hello"; return 1; }()};"
| clang-format
int i{[]() constexpr noexcept {std::cout << hello;
return 1;
}
()
}
;


Removing constexpr specifier results in a valid-looking format: 
$ echo "int i{[]() noexcept { std::cout << "hello"; return 1; }()};" |
clang-format
int i{[]() noexcept {
  std::cout << hello;
  return 1;
}()};


Workaround: adding more parentheses around lambda definition also helps:

$ echo "int i{([]() constexpr noexcept { std::cout << "hello"; return 1;
})()};" | clang-format
int i{([]() constexpr noexcept {
  std::cout << hello;
  return 1;
})()};

-- 
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/20200916/589cd093/attachment.html>


More information about the llvm-bugs mailing list