clang-format-12

This commit is contained in:
Tatsuhiro Tsujikawa 2021-08-04 15:02:20 +09:00
parent 31253f400d
commit 29cbf8b83f
10 changed files with 80 additions and 42 deletions

View File

@ -2,16 +2,18 @@
Language: Cpp Language: Cpp
AccessModifierOffset: -2 AccessModifierOffset: -2
AlignAfterOpenBracket: Align AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false AlignConsecutiveMacros: None
AlignConsecutiveAssignments: false AlignConsecutiveAssignments: None
AlignConsecutiveDeclarations: false AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right AlignEscapedNewlines: Right
AlignOperands: true AlignOperands: Align
AlignTrailingComments: true AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All AllowShortLambdasOnASingleLine: All
@ -21,12 +23,14 @@ AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true BinPackArguments: true
BinPackParameters: true BinPackParameters: true
BraceWrapping: BraceWrapping:
AfterCaseLabel: false AfterCaseLabel: false
AfterClass: false AfterClass: false
AfterControlStatement: false AfterControlStatement: Never
AfterEnum: false AfterEnum: false
AfterFunction: false AfterFunction: false
AfterNamespace: false AfterNamespace: false
@ -36,11 +40,14 @@ BraceWrapping:
AfterExternBlock: false AfterExternBlock: false
BeforeCatch: false BeforeCatch: false
BeforeElse: false BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false IndentBraces: false
SplitEmptyFunction: true SplitEmptyFunction: true
SplitEmptyRecord: true SplitEmptyRecord: true
SplitEmptyNamespace: true SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Attach BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon BreakInheritanceList: BeforeColon
@ -56,27 +63,43 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4 ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4 ContinuationIndentWidth: 4
Cpp11BracedListStyle: true Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false DerivePointerAlignment: false
DisableFormat: false DisableFormat: false
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true FixNamespaceComments: true
ForEachMacros: ForEachMacros:
- foreach - foreach
- Q_FOREACH - Q_FOREACH
- BOOST_FOREACH - BOOST_FOREACH
StatementAttributeLikeMacros:
- Q_EMIT
IncludeBlocks: Preserve IncludeBlocks: Preserve
IncludeCategories: IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2 Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|isl|json)/)' - Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3 Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*' - Regex: '.*'
Priority: 1 Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '$' IncludeIsMainRegex: '$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: AfterHash IndentPPDirectives: AfterHash
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 2 IndentWidth: 2
IndentWrappedFunctionNames: false IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave JavaScriptQuotes: Leave
JavaScriptWrapImports: true JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true KeepEmptyLinesAtTheStartOfBlocks: true
@ -86,6 +109,7 @@ MaxEmptyLinesToKeep: 1
NamespaceIndentation: None NamespaceIndentation: None
ObjCBinPackProtocolList: Auto ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2 ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2 PenaltyBreakAssignment: 2
@ -96,31 +120,46 @@ PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10 PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000 PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60 PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Right PointerAlignment: Right
ReflowComments: true ReflowComments: true
SortIncludes: false SortIncludes: false
SortJavaStaticImport: Before
SortUsingDeclarations: true SortUsingDeclarations: true
SpaceAfterCStyleCast: false SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements SpaceBeforeParens: ControlStatements
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1 SpacesBeforeTrailingComments: 1
SpacesInAngles: false SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false SpacesInCStyleCastParentheses: false
SpacesInParentheses: false SpacesInParentheses: false
SpacesInSquareBrackets: false SpacesInSquareBrackets: false
Standard: Cpp11 SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementMacros: StatementMacros:
- Q_UNUSED - Q_UNUSED
- QT_REQUIRE_VERSION - QT_REQUIRE_VERSION
TabWidth: 8 TabWidth: 8
UseCRLF: false
UseTab: Never UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
... ...

View File

@ -26,7 +26,7 @@ Coding style
We use clang-format to format source code consistently. The We use clang-format to format source code consistently. The
clang-format configuration file .clang-format is located at the root clang-format configuration file .clang-format is located at the root
directory. Since clang-format produces slightly different results directory. Since clang-format produces slightly different results
between versions, we currently use clang-format-10. between versions, we currently use clang-format-12.
To detect any violation to the coding style, we recommend to setup git To detect any violation to the coding style, we recommend to setup git
pre-commit hook to check coding style of the changes you introduced. pre-commit hook to check coding style of the changes you introduced.
@ -34,7 +34,7 @@ The pre-commit file is located at the root directory. Copy it under
.git/hooks and make sure that it is executable. The pre-commit script .git/hooks and make sure that it is executable. The pre-commit script
uses clang-format-diff.py to detect any style errors. If it is not in uses clang-format-diff.py to detect any style errors. If it is not in
your PATH or it exists under different name (e.g., your PATH or it exists under different name (e.g.,
clang-format-diff-10 in debian), either add it to PATH variable or add clang-format-diff-12 in debian), either add it to PATH variable or add
git option ``clangformatdiff.binary`` to point to the script. git option ``clangformatdiff.binary`` to point to the script.
For emacs users, integrating clang-format to emacs is very easy. For emacs users, integrating clang-format to emacs is very easy.

View File

@ -6430,8 +6430,9 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in,
/* CONTINUATION won't bear NGHTTP2_PADDED flag */ /* CONTINUATION won't bear NGHTTP2_PADDED flag */
iframe->frame.hd.flags = (uint8_t)( iframe->frame.hd.flags =
iframe->frame.hd.flags | (cont_hd.flags & NGHTTP2_FLAG_END_HEADERS)); (uint8_t)(iframe->frame.hd.flags |
(cont_hd.flags & NGHTTP2_FLAG_END_HEADERS));
iframe->frame.hd.length += cont_hd.length; iframe->frame.hd.length += cont_hd.length;
busy = 1; busy = 1;

View File

@ -197,7 +197,7 @@ inline size_t concat_string_ref_count(size_t acc) { return acc; }
// accumulated, and passed to the next function. // accumulated, and passed to the next function.
template <typename... Args> template <typename... Args>
size_t concat_string_ref_count(size_t acc, const StringRef &value, size_t concat_string_ref_count(size_t acc, const StringRef &value,
Args &&... args) { Args &&...args) {
return concat_string_ref_count(acc + value.size(), return concat_string_ref_count(acc + value.size(),
std::forward<Args>(args)...); std::forward<Args>(args)...);
} }
@ -212,7 +212,7 @@ inline uint8_t *concat_string_ref_copy(uint8_t *p) { return p; }
// beyond the last byte written. // beyond the last byte written.
template <typename... Args> template <typename... Args>
uint8_t *concat_string_ref_copy(uint8_t *p, const StringRef &value, uint8_t *concat_string_ref_copy(uint8_t *p, const StringRef &value,
Args &&... args) { Args &&...args) {
p = std::copy(std::begin(value), std::end(value), p); p = std::copy(std::begin(value), std::end(value), p);
return concat_string_ref_copy(p, std::forward<Args>(args)...); return concat_string_ref_copy(p, std::forward<Args>(args)...);
} }
@ -220,7 +220,7 @@ uint8_t *concat_string_ref_copy(uint8_t *p, const StringRef &value,
// Returns the string which is the concatenation of |args| in the // Returns the string which is the concatenation of |args| in the
// given order. The resulting string will be NULL-terminated. // given order. The resulting string will be NULL-terminated.
template <typename BlockAllocator, typename... Args> template <typename BlockAllocator, typename... Args>
StringRef concat_string_ref(BlockAllocator &alloc, Args &&... args) { StringRef concat_string_ref(BlockAllocator &alloc, Args &&...args) {
size_t len = concat_string_ref_count(0, std::forward<Args>(args)...); size_t len = concat_string_ref_count(0, std::forward<Args>(args)...);
auto dst = static_cast<uint8_t *>(alloc.alloc(len + 1)); auto dst = static_cast<uint8_t *>(alloc.alloc(len + 1));
auto p = dst; auto p = dst;
@ -237,7 +237,7 @@ StringRef concat_string_ref(BlockAllocator &alloc, Args &&... args) {
// then just call concat_string_ref(). // then just call concat_string_ref().
template <typename BlockAllocator, typename... Args> template <typename BlockAllocator, typename... Args>
StringRef realloc_concat_string_ref(BlockAllocator &alloc, StringRef realloc_concat_string_ref(BlockAllocator &alloc,
const StringRef &value, Args &&... args) { const StringRef &value, Args &&...args) {
if (value.empty()) { if (value.empty()) {
return concat_string_ref(alloc, std::forward<Args>(args)...); return concat_string_ref(alloc, std::forward<Args>(args)...);
} }

View File

@ -97,7 +97,7 @@ generator_cb deferred_generator() {
} }
template <typename F, typename... T> template <typename F, typename... T>
std::shared_ptr<Defer<F, T...>> defer_shared(F &&f, T &&... t) { std::shared_ptr<Defer<F, T...>> defer_shared(F &&f, T &&...t) {
return std::make_shared<Defer<F, T...>>(std::forward<F>(f), return std::make_shared<Defer<F, T...>>(std::forward<F>(f),
std::forward<T>(t)...); std::forward<T>(t)...);
} }

View File

@ -75,7 +75,7 @@ public:
serve_mux &mux, serve_mux &mux,
const boost::posix_time::time_duration &tls_handshake_timeout, const boost::posix_time::time_duration &tls_handshake_timeout,
const boost::posix_time::time_duration &read_timeout, const boost::posix_time::time_duration &read_timeout,
SocketArgs &&... args) SocketArgs &&...args)
: socket_(std::forward<SocketArgs>(args)...), : socket_(std::forward<SocketArgs>(args)...),
mux_(mux), mux_(mux),
deadline_(GET_IO_SERVICE(socket_)), deadline_(GET_IO_SERVICE(socket_)),

View File

@ -198,9 +198,9 @@ StringRef Request::get_real_host() const {
uint16_t Request::get_real_port() const { uint16_t Request::get_real_port() const {
auto scheme = get_real_scheme(); auto scheme = get_real_scheme();
return config.host_override.empty() return config.host_override.empty() ? util::has_uri_field(u, UF_PORT) ? u.port
? util::has_uri_field(u, UF_PORT) ? u.port : scheme == "https" ? 443
: scheme == "https" ? 443 : 80 : 80
: config.port_override == 0 ? scheme == "https" ? 443 : 80 : config.port_override == 0 ? scheme == "https" ? 443 : 80
: config.port_override; : config.port_override;
} }
@ -1681,8 +1681,9 @@ void update_html_parser(HttpClient *client, Request *req, const uint8_t *data,
continue; continue;
} }
auto link_port = auto link_port = util::has_uri_field(u, UF_PORT) ? u.port
util::has_uri_field(u, UF_PORT) ? u.port : scheme == "https" ? 443 : 80; : scheme == "https" ? 443
: 80;
if (port != link_port) { if (port != link_port) {
continue; continue;

View File

@ -1070,8 +1070,7 @@ Http2Upstream::Http2Upstream(ClientHandler *handler)
<< nghttp2_strerror(rv); << nghttp2_strerror(rv);
} }
auto window_size = auto window_size = faddr->alt_mode != UpstreamAltMode::NONE
faddr->alt_mode != UpstreamAltMode::NONE
? std::numeric_limits<int32_t>::max() ? std::numeric_limits<int32_t>::max()
: http2conf.upstream.optimize_window_size : http2conf.upstream.optimize_window_size
? std::min(http2conf.upstream.connection_window_size, ? std::min(http2conf.upstream.connection_window_size,

View File

@ -595,12 +595,10 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv,
auto downstream_addr = downstream->get_addr(); auto downstream_addr = downstream->get_addr();
auto method = req.method == -1 ? StringRef::from_lit("<unknown>") auto method = req.method == -1 ? StringRef::from_lit("<unknown>")
: http2::to_method_string(req.method); : http2::to_method_string(req.method);
auto path = req.method == HTTP_CONNECT auto path =
? req.authority req.method == HTTP_CONNECT ? req.authority
: config->http2_proxy : config->http2_proxy ? construct_absolute_request_uri(balloc, req)
? construct_absolute_request_uri(balloc, req) : req.path.empty() ? req.method == HTTP_OPTIONS ? StringRef::from_lit("*")
: req.path.empty() ? req.method == HTTP_OPTIONS
? StringRef::from_lit("*")
: StringRef::from_lit("-") : StringRef::from_lit("-")
: req.path; : req.path;
auto path_without_query = auto path_without_query =

View File

@ -45,7 +45,7 @@ template <typename... T>
constexpr std::array< constexpr std::array<
typename std::decay<typename std::common_type<T...>::type>::type, typename std::decay<typename std::common_type<T...>::type>::type,
sizeof...(T)> sizeof...(T)>
make_array(T &&... t) { make_array(T &&...t) {
return std::array< return std::array<
typename std::decay<typename std::common_type<T...>::type>::type, typename std::decay<typename std::common_type<T...>::type>::type,
sizeof...(T)>{{std::forward<T>(t)...}}; sizeof...(T)>{{std::forward<T>(t)...}};
@ -62,7 +62,7 @@ template <typename T, size_t N> constexpr size_t str_size(T (&)[N]) {
// inspired by <http://blog.korfuri.fr/post/go-defer-in-cpp/>, but our // inspired by <http://blog.korfuri.fr/post/go-defer-in-cpp/>, but our
// template can take functions returning other than void. // template can take functions returning other than void.
template <typename F, typename... T> struct Defer { template <typename F, typename... T> struct Defer {
Defer(F &&f, T &&... t) Defer(F &&f, T &&...t)
: f(std::bind(std::forward<F>(f), std::forward<T>(t)...)) {} : f(std::bind(std::forward<F>(f), std::forward<T>(t)...)) {}
Defer(Defer &&o) noexcept : f(std::move(o.f)) {} Defer(Defer &&o) noexcept : f(std::move(o.f)) {}
~Defer() { f(); } ~Defer() { f(); }
@ -72,7 +72,7 @@ template <typename F, typename... T> struct Defer {
std::function<ResultType()> f; std::function<ResultType()> f;
}; };
template <typename F, typename... T> Defer<F, T...> defer(F &&f, T &&... t) { template <typename F, typename... T> Defer<F, T...> defer(F &&f, T &&...t) {
return Defer<F, T...>(std::forward<F>(f), std::forward<T>(t)...); return Defer<F, T...>(std::forward<F>(f), std::forward<T>(t)...);
} }