[PATCH] D79773: [clang-format] Improve clang-formats handling of concepts

Johel Ernesto Guerrero Peña via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 1 11:54:38 PDT 2020


JohelEGP added a comment.

In D79773#2125040 <https://reviews.llvm.org/D79773#2125040>, @MyDeveloperDay wrote:

> Just so I'm clear for this and your Allman coment would you show me what you are seeing and what you expect to see? just so I understand.


Sure, thank you.

This is what I have, as shown above. Actually fixed to show surrounding context, which is relevant to formatting. Note the `//` comment:

  namespace jge
  {
  template <std::regular Rep>
  struct [[nodiscard]] size2d
  {
      template <class D, class U, class Rep2>
      friend constexpr auto
      operator*(const size2d& l, const units::quantity<D, U, Rep2>& r) noexcept(
          noexcept(l.w* r)) requires(requires { l.w* r; }) //
      {
          return size2d<decltype(l.w() * r)>{l.w * r, l.h * r};
      }
  };
  
  } // namespace jge

I added `//` to make the formatting look like what I want. If I remove it, this is what I get:

  namespace jge
  {
  template <std::regular Rep>
  struct [[nodiscard]] size2d
  {
      template <class D, class U, class Rep2>
      friend constexpr auto
      operator*(const size2d& l, const units::quantity<D, U, Rep2>& r) noexcept(
          noexcept(l.w* r)) requires(requires { l.w* r; }) {
          return size2d<decltype(l.w() * r)>{l.w * r, l.h * r};
      }
  };
  
  } // namespace jge

So this is what I want, without the `//` comment:

  namespace jge
  {
  template <std::regular Rep>
  struct [[nodiscard]] size2d
  {
      template <class D, class U, class Rep2>
      friend constexpr auto
      operator*(const size2d& l, const units::quantity<D, U, Rep2>& r) noexcept(
          noexcept(l.w* r)) requires(requires { l.w* r; }) 
      {
          return size2d<decltype(l.w() * r)>{l.w * r, l.h * r};
      }
  };
  
  } // namespace jge

For the constructor initializer list, this is what I have. Note the parentheses in the first requires-clause:

  namespace jge
  {
  template <class T>
  class [[nodiscard]] plane
  {
      constexpr plane(const plane& other) noexcept(
          (detail::default_allocator_is_nothrow &&
           std::is_nothrow_copy_constructible_v<T>)) requires(std::copyable<T>)
        : plane{to1d(other), other.sz.w}
      {
      }
  
      constexpr plane& operator=(const plane& other) noexcept(
          (std::is_nothrow_copy_constructible_v<plane> &&
           std::is_nothrow_copy_assignable_v<T>)) requires std::copyable<T> //
      {
          assign(to1d(other), other.sz.w);
          return *this;
      }
  };
  
  } // namespace jge

This is what I get without the parentheses. Note that all code after the constructor initializer list is further indented:

  namespace jge
  {
  template <class T>
  class [[nodiscard]] plane
  {
      constexpr plane(const plane& other) noexcept(
          (detail::default_allocator_is_nothrow &&
           std::is_nothrow_copy_constructible_v<T>)) requires std::copyable<T>
        : plane{to1d(other), other.sz.w}
        {
        }
  
        constexpr plane& operator=(const plane& other) noexcept(
            (std::is_nothrow_copy_constructible_v<plane> &&
             std::is_nothrow_copy_assignable_v<T>)) requires std::copyable<T> //
        {
            assign(to1d(other), other.sz.w);
            return *this;
        }
  };
  
  } // namespace jge

So this is what I want. Without extra parentheses, nor extra indentation:

  namespace jge
  {
  template <class T>
  class [[nodiscard]] plane
  {
      constexpr plane(const plane& other) noexcept(
          (detail::default_allocator_is_nothrow &&
           std::is_nothrow_copy_constructible_v<T>)) requires std::copyable<T>
        : plane{to1d(other), other.sz.w}
      {
      }
  
      constexpr plane& operator=(const plane& other) noexcept(
          (std::is_nothrow_copy_constructible_v<plane> &&
           std::is_nothrow_copy_assignable_v<T>)) requires std::copyable<T> //
      {
          assign(to1d(other), other.sz.w);
          return *this;
      }
  };
  
  } // namespace jge

All with the config file <https://gist.github.com/johelegp/6cf4c287e86cf5e3b90769bcd100ba39> linked above.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79773/new/

https://reviews.llvm.org/D79773





More information about the cfe-commits mailing list