diff --git a/.clang-format b/.clang-format index 97cbfbed..22d336a6 100644 --- a/.clang-format +++ b/.clang-format @@ -2,16 +2,18 @@ Language: Cpp AccessModifierOffset: -2 AlignAfterOpenBracket: Align -AlignConsecutiveMacros: false -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false +AlignConsecutiveMacros: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None AlignEscapedNewlines: Right -AlignOperands: true +AlignOperands: Align AlignTrailingComments: true AllowAllArgumentsOnNextLine: true AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: All AllowShortLambdasOnASingleLine: All @@ -21,12 +23,14 @@ AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability BinPackArguments: true BinPackParameters: true BraceWrapping: AfterCaseLabel: false AfterClass: false - AfterControlStatement: false + AfterControlStatement: Never AfterEnum: false AfterFunction: false AfterNamespace: false @@ -36,11 +40,14 @@ BraceWrapping: AfterExternBlock: false BeforeCatch: false BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false IndentBraces: false SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: true BreakBeforeBraces: Attach BreakBeforeInheritanceComma: false BreakInheritanceList: BeforeColon @@ -56,27 +63,43 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true +DeriveLineEnding: true DerivePointerAlignment: false DisableFormat: false +EmptyLineBeforeAccessModifier: LogicalBlock ExperimentalAutoDetectBinPacking: false FixNamespaceComments: true ForEachMacros: - foreach - Q_FOREACH - BOOST_FOREACH +StatementAttributeLikeMacros: + - Q_EMIT IncludeBlocks: Preserve IncludeCategories: - Regex: '^"(llvm|llvm-c|clang|clang-c)/' Priority: 2 + SortPriority: 0 + CaseSensitive: false - Regex: '^(<|"(gtest|isl|json)/)' Priority: 3 + SortPriority: 0 + CaseSensitive: false - Regex: '.*' Priority: 1 + SortPriority: 0 + CaseSensitive: false IncludeIsMainRegex: '$' +IncludeIsMainSourceRegex: '' IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true IndentPPDirectives: AfterHash +IndentExternBlock: AfterExternBlock +IndentRequires: false IndentWidth: 2 IndentWrappedFunctionNames: false +InsertTrailingCommas: None JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: true @@ -86,6 +109,7 @@ MaxEmptyLinesToKeep: 1 NamespaceIndentation: None ObjCBinPackProtocolList: Auto ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true PenaltyBreakAssignment: 2 @@ -96,31 +120,46 @@ PenaltyBreakString: 1000 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 +PenaltyIndentedWhitespace: 0 PointerAlignment: Right ReflowComments: true SortIncludes: false +SortJavaStaticImport: Before SortUsingDeclarations: true SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements +SpaceAroundPointerQualifiers: Default SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 1 SpacesInAngles: false +SpacesInConditionalStatement: false SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: Cpp11 +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Latest StatementMacros: - Q_UNUSED - QT_REQUIRE_VERSION TabWidth: 8 +UseCRLF: false UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME ... diff --git a/doc/sources/contribute.rst b/doc/sources/contribute.rst index 801a400e..a5330ec9 100644 --- a/doc/sources/contribute.rst +++ b/doc/sources/contribute.rst @@ -26,7 +26,7 @@ Coding style We use clang-format to format source code consistently. The clang-format configuration file .clang-format is located at the root 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 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 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., -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. For emacs users, integrating clang-format to emacs is very easy. diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 1a2b00d3..36f1179f 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -6430,8 +6430,9 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, /* CONTINUATION won't bear NGHTTP2_PADDED flag */ - iframe->frame.hd.flags = (uint8_t)( - iframe->frame.hd.flags | (cont_hd.flags & NGHTTP2_FLAG_END_HEADERS)); + iframe->frame.hd.flags = + (uint8_t)(iframe->frame.hd.flags | + (cont_hd.flags & NGHTTP2_FLAG_END_HEADERS)); iframe->frame.hd.length += cont_hd.length; busy = 1; diff --git a/src/allocator.h b/src/allocator.h index 6ad83522..89250d42 100644 --- a/src/allocator.h +++ b/src/allocator.h @@ -197,7 +197,7 @@ inline size_t concat_string_ref_count(size_t acc) { return acc; } // accumulated, and passed to the next function. template size_t concat_string_ref_count(size_t acc, const StringRef &value, - Args &&... args) { + Args &&...args) { return concat_string_ref_count(acc + value.size(), std::forward(args)...); } @@ -212,7 +212,7 @@ inline uint8_t *concat_string_ref_copy(uint8_t *p) { return p; } // beyond the last byte written. template 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); return concat_string_ref_copy(p, std::forward(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 // given order. The resulting string will be NULL-terminated. template -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)...); auto dst = static_cast(alloc.alloc(len + 1)); auto p = dst; @@ -237,7 +237,7 @@ StringRef concat_string_ref(BlockAllocator &alloc, Args &&... args) { // then just call concat_string_ref(). template StringRef realloc_concat_string_ref(BlockAllocator &alloc, - const StringRef &value, Args &&... args) { + const StringRef &value, Args &&...args) { if (value.empty()) { return concat_string_ref(alloc, std::forward(args)...); } diff --git a/src/asio_common.cc b/src/asio_common.cc index 90762d3d..428dbd62 100644 --- a/src/asio_common.cc +++ b/src/asio_common.cc @@ -97,7 +97,7 @@ generator_cb deferred_generator() { } template -std::shared_ptr> defer_shared(F &&f, T &&... t) { +std::shared_ptr> defer_shared(F &&f, T &&...t) { return std::make_shared>(std::forward(f), std::forward(t)...); } diff --git a/src/asio_server_connection.h b/src/asio_server_connection.h index daf9a664..a9489658 100644 --- a/src/asio_server_connection.h +++ b/src/asio_server_connection.h @@ -75,7 +75,7 @@ public: serve_mux &mux, const boost::posix_time::time_duration &tls_handshake_timeout, const boost::posix_time::time_duration &read_timeout, - SocketArgs &&... args) + SocketArgs &&...args) : socket_(std::forward(args)...), mux_(mux), deadline_(GET_IO_SERVICE(socket_)), diff --git a/src/nghttp.cc b/src/nghttp.cc index 81e7ebe9..30ef26d3 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -198,11 +198,11 @@ StringRef Request::get_real_host() const { uint16_t Request::get_real_port() const { auto scheme = get_real_scheme(); - return config.host_override.empty() - ? util::has_uri_field(u, UF_PORT) ? u.port - : scheme == "https" ? 443 : 80 - : config.port_override == 0 ? scheme == "https" ? 443 : 80 - : config.port_override; + return config.host_override.empty() ? util::has_uri_field(u, UF_PORT) ? u.port + : scheme == "https" ? 443 + : 80 + : config.port_override == 0 ? scheme == "https" ? 443 : 80 + : config.port_override; } void Request::init_html_parser() { @@ -1681,8 +1681,9 @@ void update_html_parser(HttpClient *client, Request *req, const uint8_t *data, continue; } - auto link_port = - util::has_uri_field(u, UF_PORT) ? u.port : scheme == "https" ? 443 : 80; + auto link_port = util::has_uri_field(u, UF_PORT) ? u.port + : scheme == "https" ? 443 + : 80; if (port != link_port) { continue; diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 9b9e5523..19d64e17 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -1070,13 +1070,12 @@ Http2Upstream::Http2Upstream(ClientHandler *handler) << nghttp2_strerror(rv); } - auto window_size = - faddr->alt_mode != UpstreamAltMode::NONE - ? std::numeric_limits::max() - : http2conf.upstream.optimize_window_size - ? std::min(http2conf.upstream.connection_window_size, - NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE) - : http2conf.upstream.connection_window_size; + auto window_size = faddr->alt_mode != UpstreamAltMode::NONE + ? std::numeric_limits::max() + : http2conf.upstream.optimize_window_size + ? std::min(http2conf.upstream.connection_window_size, + NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE) + : http2conf.upstream.connection_window_size; rv = nghttp2_session_set_local_window_size(session_, NGHTTP2_FLAG_NONE, 0, window_size); diff --git a/src/shrpx_log.cc b/src/shrpx_log.cc index 0c2eae7a..8fd8b11c 100644 --- a/src/shrpx_log.cc +++ b/src/shrpx_log.cc @@ -595,14 +595,12 @@ void upstream_accesslog(const std::vector &lfv, auto downstream_addr = downstream->get_addr(); auto method = req.method == -1 ? StringRef::from_lit("") : http2::to_method_string(req.method); - auto path = req.method == HTTP_CONNECT - ? req.authority - : config->http2_proxy - ? construct_absolute_request_uri(balloc, req) - : req.path.empty() ? req.method == HTTP_OPTIONS - ? StringRef::from_lit("*") - : StringRef::from_lit("-") - : req.path; + auto path = + req.method == HTTP_CONNECT ? req.authority + : config->http2_proxy ? construct_absolute_request_uri(balloc, req) + : req.path.empty() ? req.method == HTTP_OPTIONS ? StringRef::from_lit("*") + : StringRef::from_lit("-") + : req.path; auto path_without_query = req.method == HTTP_CONNECT ? path diff --git a/src/template.h b/src/template.h index b2f850d6..530a1d13 100644 --- a/src/template.h +++ b/src/template.h @@ -45,7 +45,7 @@ template constexpr std::array< typename std::decay::type>::type, sizeof...(T)> -make_array(T &&... t) { +make_array(T &&...t) { return std::array< typename std::decay::type>::type, sizeof...(T)>{{std::forward(t)...}}; @@ -62,7 +62,7 @@ template constexpr size_t str_size(T (&)[N]) { // inspired by , but our // template can take functions returning other than void. template struct Defer { - Defer(F &&f, T &&... t) + Defer(F &&f, T &&...t) : f(std::bind(std::forward(f), std::forward(t)...)) {} Defer(Defer &&o) noexcept : f(std::move(o.f)) {} ~Defer() { f(); } @@ -72,7 +72,7 @@ template struct Defer { std::function f; }; -template Defer defer(F &&f, T &&... t) { +template Defer defer(F &&f, T &&...t) { return Defer(std::forward(f), std::forward(t)...); }