[PATCH] D116007: [clang-format] Fix BreakBeforeBraces: Attach ignored with trailing requires-expression of function.

Johel Ernesto Guerrero Peña via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 20 06:11:07 PST 2021


JohelEGP added a comment.

Thank you for doing this.

With the patch, I get this diff:

  diff
  diff --git a/sources/details/waarudo.details.utilities.cpp b/sources/details/waarudo.details.utilities.cpp
  index 0b3680e..6e234ac 100644
  --- a/sources/details/waarudo.details.utilities.cpp
  +++ b/sources/details/waarudo.details.utilities.cpp
  @@ -7,8 +7,8 @@ namespace waarudo {
   
   export template<class T, template<class...> class U> concept specialization_of = //
     (requires(T v) {
  -    []<class... V>(U<V...>) requires std::same_as<T, U<V...>> { }
  -    (v);
  +    []<class... V>(U<V...>) requires std::same_as<T, U<V...>> {
  +    }(v);
     });
   
   template<class T, class U> concept value_trait_for = //
  diff --git a/sources/waarudo.quantities.cpp b/sources/waarudo.quantities.cpp
  index 83a17db..fdc4c53 100644
  --- a/sources/waarudo.quantities.cpp
  +++ b/sources/waarudo.quantities.cpp
  @@ -52,12 +52,20 @@ export template<class Id, number Number> struct quantity {
       requires std::convertible_to<const Number&, Number2>
     [[nodiscard]] constexpr operator quantity<Id, Number2>() const { return {number}; }
   
  -  constexpr quantity& operator++() & requires ordered_number<Number> { return ++number, *this; }
  -  constexpr quantity& operator--() & requires ordered_number<Number> { return --number, *this; }
  -  [[nodiscard]] constexpr quantity operator++(int) & requires ordered_number<Number> { return {number++}; }
  -  [[nodiscard]] constexpr quantity operator--(int) & requires ordered_number<Number> { return {number--}; }
  +  constexpr quantity& operator++() & requires ordered_number<Number> {
  +    return ++number, *this;
  +  } constexpr quantity& operator--() & requires ordered_number<Number> {
  +    return --number, *this;
  +  } [[nodiscard]] constexpr quantity operator++(int) & requires ordered_number<Number> {
  +    return {number++};
  +  } [[nodiscard]] constexpr quantity operator--(int) & requires ordered_number<Number> {
  +    return {number--};
  +  }
   
  -  constexpr quantity& operator+=(const relative_quantity_for<quantity> auto& d) & { return number += d.number, *this; }
  +  constexpr quantity&
  +  operator+=(const relative_quantity_for<quantity> auto& d) & {
  +    return number += d.number, *this;
  +  }
     constexpr quantity& operator-=(const relative_quantity_for<quantity> auto& d) & { return number -= d.number, *this; }
   
     template<relative_quantity_for<quantity> Q>

Here's how it looks without the patch:

  namespace waarudo {
  
  export template<class T, template<class...> class U> concept specialization_of = //
    (requires(T v) {
      []<class... V>(U<V...>) requires std::same_as<T, U<V...>> { }
      (v);
    });
  
  struct x {
    constexpr quantity& operator++() & requires ordered_number<Number> { return ++number, *this; }
    constexpr quantity& operator--() & requires ordered_number<Number> { return --number, *this; }
    [[nodiscard]] constexpr quantity operator++(int) & requires ordered_number<Number> { return {number++}; }
    [[nodiscard]] constexpr quantity operator--(int) & requires ordered_number<Number> { return {number--}; }
  
    constexpr quantity& operator+=(const relative_quantity_for<quantity> auto& d) & { return number += d.number, *this; }
    constexpr quantity& operator-=(const relative_quantity_for<quantity> auto& d) & { return number -= d.number, *this; }
  };
  
  } // namespace waarudo

Here's my `.clang-format`:

  AccessModifierOffset: -2
  AlignAfterOpenBracket: AlwaysBreak
  AlignArrayOfStructures: None
  AlignConsecutiveAssignments: Consecutive
  AlignConsecutiveBitFields: true
  AlignConsecutiveDeclarations: false
  AlignEscapedNewlines: Right
  AlignOperands: Align
  AlignTrailingComments: true
  AllowAllArgumentsOnNextLine: true
  AllowAllConstructorInitializersOnNextLine: true
  AllowAllParametersOfDeclarationOnNextLine: true
  AllowShortBlocksOnASingleLine: Always
  AllowShortCaseLabelsOnASingleLine: true
  AllowShortEnumsOnASingleLine: true
  AllowShortFunctionsOnASingleLine: All
  AllowShortIfStatementsOnASingleLine: AllIfsAndElse
  AllowShortLambdasOnASingleLine: All
  AllowShortLoopsOnASingleLine: true
  AlwaysBreakAfterReturnType: None
  AlwaysBreakBeforeMultilineStrings: false
  AlwaysBreakTemplateDeclarations: No
  BinPackArguments: true
  BinPackParameters: true
  BitFieldColonSpacing: Both
  BreakBeforeBinaryOperators: None
  BreakBeforeBraces: Attach
  BreakBeforeConceptDeclarations: false
  BreakBeforeTernaryOperators: true
  BreakConstructorInitializers: BeforeColon
  BreakInheritanceList: BeforeColon
  BreakStringLiterals: true
  ColumnLimit: 120
  ConstructorInitializerAllOnOneLineOrOnePerLine: true
  ConstructorInitializerIndentWidth: 2
  ContinuationIndentWidth: 2
  Cpp11BracedListStyle: true
  DeriveLineEnding: false
  DerivePointerAlignment: false
  DisableFormat: false
  EmptyLineAfterAccessModifier: Never
  EmptyLineBeforeAccessModifier: Always
  FixNamespaceComments: true
  IncludeBlocks: Preserve
  IncludeCategories:
    - Regex:      '<(experimental/)?[a-z_]+>' # C++ standard library
      Priority:   1
  IndentAccessModifiers: false
  IndentCaseBlocks: false
  IndentCaseLabels: false
  IndentPPDirectives: AfterHash
  IndentRequires: true
  IndentWidth: 2
  IndentWrappedFunctionNames: false
  KeepEmptyLinesAtTheStartOfBlocks: false
  Language: Cpp
  MaxEmptyLinesToKeep: 1
  NamespaceIndentation: Inner
  PointerAlignment: Left
  PPIndentWidth: -1
  ReflowComments: true
  ShortNamespaceLines: 0
  SortIncludes: CaseInsensitive
  SortUsingDeclarations: true
  SpaceAfterLogicalNot: true
  SpaceAfterTemplateKeyword: false
  SpaceBeforeAssignmentOperators: true
  SpaceBeforeCaseColon: false
  SpaceBeforeCpp11BracedList: false
  SpaceBeforeCtorInitializerColon: true
  SpaceBeforeInheritanceColon: true
  SpaceBeforeParens: ControlStatements
  SpaceBeforeRangeBasedForLoopColon: true
  SpaceBeforeSquareBrackets: false
  SpaceInEmptyBlock: true
  SpaceInEmptyParentheses: false
  SpacesBeforeTrailingComments: 1
  SpacesInAngles: false
  SpacesInConditionalStatement: false
  SpacesInLineCommentPrefix:
    Minimum: 1
    Maximum: 1
  SpacesInParentheses: false
  SpacesInSquareBrackets: false
  Standard: Latest
  TabWidth: 2
  UseCRLF: false
  UseTab: Never

The second file in the diff, `sources/waarudo.quantities.cpp`, has a problem. The problem is that I've built my `.clang-format` to minimize line breaks, but for some reason, what fit on a line before, now doesn't.
On inspection, its first diff does not insert a line break before the start of new functions. Its second diff changes just the first function. If I remove the lines in the previous diff so that `x` only has operators `+=` and `-=`, they remain unchanged.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116007



More information about the cfe-commits mailing list