Skip to content

Commit 8f81155

Browse files
authored
Support Clang format 15 (#155)
* Support Clang Format 15 This version mostly add support for the C++20 `requires` clause. * Fix C++ standard used in Clang Format config
1 parent b3dd4fd commit 8f81155

File tree

9 files changed

+170
-11
lines changed

9 files changed

+170
-11
lines changed

.bbp-project.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
tools:
22
ClangFormat:
33
enable: True
4-
version: ~=14.0
4+
version: ~=15.0
55
CMakeFormat:
66
enable: True
77
Flake8:

cpp/clang-format-13

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ SpacesInContainerLiterals: false
9696
SpacesInCStyleCastParentheses: false
9797
SpacesInParentheses: false # '(' style
9898
SpacesInSquareBrackets: false
99-
Standard: c++14
99+
Standard: c++17
100100
TabWidth: 4
101101
UseTab: Never
102102
...

cpp/clang-format-14

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ SpacesInContainerLiterals: false
100100
SpacesInCStyleCastParentheses: false
101101
SpacesInParentheses: false # '(' style
102102
SpacesInSquareBrackets: false
103-
Standard: c++14
103+
Standard: c++17
104104
TabWidth: 4
105105
UseTab: Never
106106
...

cpp/clang-format-15

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
AccessModifierOffset: -2
3+
AlignAfterOpenBracket: Align
4+
AlignArrayOfStructures: None
5+
AlignConsecutiveAssignments: false
6+
AlignConsecutiveDeclarations: false
7+
AlignConsecutiveMacros: true
8+
AlignEscapedNewlinesLeft: true
9+
AlignOperands: true
10+
AlignTrailingComments: true
11+
AllowAllParametersOfDeclarationOnNextLine: false
12+
AllowShortBlocksOnASingleLine: false
13+
AllowShortCaseLabelsOnASingleLine: false
14+
AllowShortFunctionsOnASingleLine: Empty
15+
AllowShortIfStatementsOnASingleLine: false
16+
AllowShortLoopsOnASingleLine: false
17+
AlwaysBreakBeforeMultilineStrings: true
18+
AlwaysBreakTemplateDeclarations: true
19+
BasedOnStyle: WebKit
20+
BinPackArguments: false
21+
BinPackParameters: false
22+
BraceWrapping:
23+
AfterClass: false
24+
AfterControlStatement: false
25+
AfterEnum: false
26+
AfterExternBlock: false
27+
AfterFunction: false
28+
AfterNamespace: false
29+
AfterStruct: false
30+
AfterUnion: false
31+
BeforeCatch: false
32+
BeforeElse: false
33+
BreakBeforeBraces: Custom
34+
BreakBeforeBinaryOperators: false
35+
BreakBeforeConceptDeclarations: true
36+
BreakBeforeTernaryOperators: true
37+
BreakConstructorInitializersBeforeComma: true
38+
BreakStringLiterals: true
39+
ColumnLimit: 100
40+
CommentPragmas: '^ IWYU pragma:'
41+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
42+
ConstructorInitializerIndentWidth: 4
43+
ContinuationIndentWidth: 4
44+
Cpp11BracedListStyle: true
45+
DerivePointerAlignment: false
46+
DerivePointerBinding: true
47+
EmptyLineBeforeAccessModifier: Leave
48+
EmptyLineAfterAccessModifier: Leave
49+
ExperimentalAutoDetectBinPacking: false
50+
FixNamespaceComments: true
51+
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
52+
IncludeCategories:
53+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
54+
Priority: 2
55+
- Regex: '^(<|"(gtest|isl|json)/)'
56+
Priority: 3
57+
- Regex: '.*'
58+
Priority: 1
59+
IncludeIsMainRegex: '$'
60+
IndentAccessModifiers: false
61+
IndentCaseLabels: false
62+
IndentPPDirectives: None
63+
IndentRequiresClause: false
64+
IndentWidth: 4
65+
IndentWrappedFunctionNames: false
66+
InsertBraces: False
67+
KeepEmptyLinesAtTheStartOfBlocks: false
68+
LambdaBodyIndentation: Signature
69+
Language: Cpp
70+
MaxEmptyLinesToKeep: 2
71+
NamespaceIndentation: None
72+
PenaltyBreakAssignment: 40
73+
PenaltyBreakBeforeFirstCallParameter: 100
74+
PenaltyBreakComment: 60
75+
PenaltyBreakFirstLessLess: 120
76+
PenaltyBreakString: 1000
77+
PenaltyExcessCharacter: 1000000
78+
PenaltyReturnTypeOnItsOwnLine: 200
79+
PointerAlignment: Left
80+
PointerBindsToType: true
81+
PPIndentWidth: -1
82+
PackConstructorInitializers: Never
83+
QualifierAlignment: Left
84+
ReflowComments: true
85+
RemoveBracesLLVM: false
86+
RequiresClausePosition: OwnLine
87+
SeparateDefinitionBlocks: Always
88+
SortIncludes: true
89+
SpaceAfterCStyleCast: true
90+
SpaceAfterTemplateKeyword: true
91+
SpaceBeforeAssignmentOperators: true
92+
SpaceBeforeCpp11BracedList: false
93+
SpaceBeforeCtorInitializerColon: false
94+
SpaceBeforeInheritanceColon: false
95+
SpaceBeforeParens: ControlStatements
96+
SpaceBeforeRangeBasedForLoopColon: false
97+
SpaceInEmptyBlock: false
98+
SpaceInEmptyParentheses: false
99+
SpacesBeforeTrailingComments: 2
100+
SpacesInAngles: false # '< ' style
101+
SpacesInContainerLiterals: false
102+
SpacesInCStyleCastParentheses: false
103+
SpacesInParentheses: false # '(' style
104+
SpacesInSquareBrackets: false
105+
Standard: c++20
106+
TabWidth: 4
107+
UseTab: Never
108+
...

cpp/formatting/README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ bool value =
367367
```cpp
368368
template <typename T>
369369
concept Hashable = requires(T a) {
370-
{ std::hash<T>{}(a) } -> std::convertible_to<std::size_t>;
371-
};
370+
{ std::hash<T>{}(a) } -> std::convertible_to<std::size_t>;
371+
};
372372

373373
```
374374
### Clang-Format configuration
@@ -455,8 +455,6 @@ void sort(It begin, It end) {
455455

456456

457457
```
458-
### Clang-Format configuration
459-
* `IndentRequires: False`
460458
461459
## Use 4 columns for indentation
462460
@@ -537,6 +535,36 @@ const int* a;
537535
### Clang-Format configuration
538536
* `QualifierAlignment: Left`
539537

538+
## The C++20 `requires` clause is put in its own line
539+
540+
### Example
541+
```cpp
542+
template <typename T>
543+
concept Addable = requires(T t) { ++t; };
544+
545+
template <typename T>
546+
requires Addable<T>
547+
struct Foo {
548+
// ...
549+
};
550+
551+
template <typename T>
552+
requires Addable<T>
553+
void bar(T t){
554+
// ...
555+
};
556+
557+
template <typename T>
558+
void baz(T t)
559+
requires Addable<T>
560+
{
561+
//...
562+
};
563+
564+
```
565+
### Clang-Format configuration
566+
* `RequiresClausePosition: OwnLine`
567+
540568
## Specifies the use of empty lines to separate definition blocks, including classes, structs,
541569
enums, and functions.
542570

cpp/formatting/formatting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def get_cf_data(line):
4646
with open(file) as istr:
4747
content = [line.rstrip() for line in istr.readlines()]
4848
# retrieve title
49-
assert is_comment(content[0])
49+
assert is_comment(content[0]), f"{file}: first line may be '// TITLE'"
5050
attrs["title"] = content[0].lstrip("//").lstrip()
5151
i = 1
5252
# eat empty lines

cpp/formatting/snippets/BreakBeforeConceptDeclarations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
template <typename T>
44
concept Hashable = requires(T a) {
5-
{ std::hash<T>{}(a) } -> std::convertible_to<std::size_t>;
6-
};
5+
{ std::hash<T>{}(a) } -> std::convertible_to<std::size_t>;
6+
};

cpp/formatting/snippets/IndentRequires.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
template <typename It>
44
requires Iterator<It>
5-
// clang-format off
5+
// clang-format off
66
void sort(It begin, It end) {
77
//....
88
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// The C++20 `requires` clause is put in its own line
2+
3+
template <typename T>
4+
concept Addable = requires(T t) { ++t; };
5+
6+
template <typename T>
7+
requires Addable<T>
8+
struct Foo {
9+
// ...
10+
};
11+
12+
template <typename T>
13+
requires Addable<T>
14+
void bar(T t){
15+
// ...
16+
};
17+
18+
template <typename T>
19+
void baz(T t)
20+
requires Addable<T>
21+
{
22+
//...
23+
};

0 commit comments

Comments
 (0)