Issue 178372
Summary [clang-format][C++] Odd formatting of constructors
Labels clang-format
Assignees
Reporter H-G-Hristov
    When formatting constructors with the LLVM style I get for the last constructor:

```c++
  _LIBCPP_HIDE_FROM_ABI constexpr basic_cstring_view() : __data_{}, __size_{0} noexcept {}
 _LIBCPP_HIDE_FROM_ABI basic_cstring_view(const basic_cstring_view&) noexcept = default;
...
  _LIBCPP_HIDE_FROM_ABI constexpr basic_cstring_view(const _CharT* __str, size_type __len) : __data_{__str}, __size_ {
    __len
  } noexcept
#      ifdef __cpp_contracts
  pre(__str != nullptr) pre(__str[__len] == '\0')
#      endif
  {
  }
```

Is this what we are supposed to get? Wouldn't this make more sense:
```c++
 _LIBCPP_HIDE_FROM_ABI constexpr basic_cstring_view() : __data_{}, __size_{0} noexcept {}
  _LIBCPP_HIDE_FROM_ABI basic_cstring_view(const basic_cstring_view&) noexcept            = default;
...
 _LIBCPP_HIDE_FROM_ABI constexpr basic_cstring_view(const _CharT* __str, size_type __len) : __data_{__str}, __size_ {__len} noexcept
#      ifdef __cpp_contracts
  pre(__str != nullptr) pre(__str[__len] == '\0')
# endif
  {}
```

OK this exceeds the max line length then something like:

```c++
  _LIBCPP_HIDE_FROM_ABI constexpr basic_cstring_view() : __data_{}, __size_{0} noexcept {}
  _LIBCPP_HIDE_FROM_ABI basic_cstring_view(const basic_cstring_view&) noexcept            = default;
...
  _LIBCPP_HIDE_FROM_ABI constexpr basic_cstring_view(const _CharT* __str, size_type __len) : __data_{__str},
    __size_ {__len} noexcept
#      ifdef __cpp_contracts
  pre(__str != nullptr) pre(__str[__len] == '\0')
#      endif
  {}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to